Hello,
I created a MainWindow and a very simple Dialog using the Qt Designer. I want to use both components with a single inheritance approach. In a Slot of the MainWindow (connected to an Action of the MainWindow) I want to create and execute an instance of the Dialog class. But when I try to compile the programm there is the error:
release\MainWindow.o(.text+0x28f):MainWindow.cpp: undefined reference to 'Dialog::Dialog(QWidget*)'
I think the proplem might be connected with the fact that I want to create the Dialog in a class derived from QMainWindow. In my project I previously created the Dialog in a Slot of a QAbstractTableModel and it worked fine. Than I decided that this class wasn't the right place to do this and wanted to create the Dialog in a slot of the MainWindow instead ending up with this error.
Here are the files of a minimal example:
MainWindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "ui_MainWindow.h"
Q_OBJECT
public:
MainWindow
(QWidget *parent
=0,Qt
::WFlags flags
=0);
public slots:
void createDialog();
private:
Ui::MainWindow *ui;
};
#endif
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "ui_MainWindow.h"
class MainWindow : public QMainWindow {
Q_OBJECT
public:
MainWindow(QWidget *parent=0,Qt::WFlags flags=0);
public slots:
void createDialog();
private:
Ui::MainWindow *ui;
};
#endif
To copy to clipboard, switch view to plain text mode
MainWindow.cpp
#include "MainWindow.h"
#include "Dialog.h"
MainWindow
::MainWindow(QWidget *parent,Qt
::WFlags flags
){ ui = new Ui::MainWindow;
ui->setupUi(this);
connect(ui->actionCreate,SIGNAL(activated()),this,SLOT(createDialog()));
}
void MainWindow::createDialog(){
Dialog *d = new Dialog;
d->exec();
}
#include "MainWindow.h"
#include "Dialog.h"
MainWindow::MainWindow(QWidget *parent,Qt::WFlags flags){
ui = new Ui::MainWindow;
ui->setupUi(this);
connect(ui->actionCreate,SIGNAL(activated()),this,SLOT(createDialog()));
}
void MainWindow::createDialog(){
Dialog *d = new Dialog;
d->exec();
}
To copy to clipboard, switch view to plain text mode
Dialog.h
#ifndef MYDIALOG_H
#define MYDIALOG_H
#include <QDialog>
#include "ui_Dialog.h"
public:
};
#endif
#ifndef MYDIALOG_H
#define MYDIALOG_H
#include <QDialog>
#include "ui_Dialog.h"
class Dialog : public QDialog {
public:
Dialog(QWidget *parent = 0);
};
#endif
To copy to clipboard, switch view to plain text mode
Dialog.cpp
#include "Dialog.h"
Ui::Dialog *ui = new Ui::Dialog;
ui.setupUi(this);
}
#include "Dialog.h"
Dialog::Dialog(QWidget *parent = 0) : QWidget(parent){
Ui::Dialog *ui = new Ui::Dialog;
ui.setupUi(this);
}
To copy to clipboard, switch view to plain text mode
Bookmarks