So I'm a newbie to Qt and I'm trying to create a simple project. I've got a MainWindow with some buttons and stuff that I created using the Qt Designer, and once I click one of these buttons (it's name is newBook), I need to open another dialog.
I was searching for some solutions, people were using "Go to slot..." options, which my Visual Studio doesn't provide. So I tried to create my own function.
The MainWindow's name is projekt2, the Dialog I want to open is named addBook.
projekt2.h
#pragma once
#include <QtWidgets/QMainWindow>
#include "ui_projekt2.h"
class projekt2 : public QMainWindow
{
Q_OBJECT
public:
projekt2(QWidget *parent = Q_NULLPTR);
private:
Ui::projekt2Class ui;
protected slots:
void projekt2::on_newBook_clicked();
};
projekt2.cpp
#include "stdafx.h"
#include "projekt2.h"
#include "addbook.h"
projekt2::projekt2(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
}
void projekt2::on_newBook_clicked()
{
addBook book(this);
book.setModal(true);
book.exec();
}
addbook.h
#pragma once
#include <QDialog>
#include "ui_addbook.h"
class addBook : public QDialog
{
Q_OBJECT
public:
addBook(QWidget *parent = Q_NULLPTR);
~addBook();
private:
Ui::addBook ui;
};
addbook.cpp
#include "stdafx.h"
#include "addbook.h"
addBook::addBook(QWidget *parent)
: QDialog(parent)
{
ui.setupUi(this);
}
addBook::~addBook()
{
}
When i run this, there are no errors. My MainWindow opens, but when I click the button, nothing happens. I'm sure I'm missing something, like a connection, but I can't figure it out.
I apologize for a trivial question, but I'm a bit frustrated now. Thanks for your patience.
ui_projekt2.h
file? – p-a-o-l-o