Hi all!
I recently started using Qt 4.6.0 to create a GUI for a computer vision program I previously coded in C...
Everything is going well - I've created my main window and that works perfectly!
All I want to do now is be able to open a dialog (created in Qt Designer) from this main window.
I've used the multiple inheritance approach (as described here) for my main window:
MainWindow.h (form has ObjectName=MainWindow in Qt Designer)
#include "ui_MainWindow.h"
class MainWin
: public QMainWindow,
private Ui
::MainWindow{
Q_OBJECT
public:
// etc.
}
#include "ui_MainWindow.h"
class MainWin : public QMainWindow, private Ui::MainWindow
{
Q_OBJECT
public:
MainWin(QWidget *parent = 0);
// etc.
}
To copy to clipboard, switch view to plain text mode
MainWindow.cpp
#include <QtGui>
#include "MainWindow.h"
#include "CameraConnectDialog.h"
{
setupUi(this);
// etc.
}
#include <QtGui>
#include "MainWindow.h"
#include "CameraConnectDialog.h"
MainWin::MainWin(QWidget *parent) : QMainWindow(parent)
{
setupUi(this);
// etc.
}
To copy to clipboard, switch view to plain text mode
main.cpp
#include <QApplication>
#include "MainWindow.h"
int main(int argc, char *argv[])
{
MainWin mainwindow;
mainwindow.show();
return app.exec();
}
#include <QApplication>
#include "MainWindow.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainWin mainwindow;
mainwindow.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
CameraConnectDialog.h (form has ObjectName=CameraConnectDialog in Qt Designer)
#include "ui_CameraConnectDialog.h"
class CameraConnectDialog
: public QDialog{
Q_OBJECT
public:
CameraConnectDialog
(QWidget *parent
= 0);
};
#include "ui_CameraConnectDialog.h"
class CameraConnectDialog : public QDialog
{
Q_OBJECT
public:
CameraConnectDialog(QWidget *parent = 0);
};
To copy to clipboard, switch view to plain text mode
CameraConnectDialog.cpp
#include <QtGui>
#include "CameraConnectDialog.h"
CameraConnectDialog
::CameraConnectDialog(QWidget *parent
) : QDialog(parent
)
{
// code to go here
}
#include <QtGui>
#include "CameraConnectDialog.h"
CameraConnectDialog::CameraConnectDialog(QWidget *parent) : QDialog(parent)
{
// code to go here
}
To copy to clipboard, switch view to plain text mode
I then attempt to open this dialog using the following in one of the member functions of class MainWin (in MainWindow.cpp):
CameraConnectDialog dialog(this);
dialog.exec();
CameraConnectDialog dialog(this);
dialog.exec();
To copy to clipboard, switch view to plain text mode
I get no compilation errors with this but when the above dialog.exec() is invoked, a blank dialog appears as opposed to the one I actually created...
My .pro file also contains all the appropriate forms and headers.
Are there any mistakes in the way I've incorporated my dialog into my main window?
I'm pulling my hair out over this and would really appreciate if someone could point my in the right direction!
Thanks!!!
Bookmarks