PDA

View Full Version : How do I use a mainwindow .ui file?



thomaspu
23rd November 2006, 03:31
Help, I'm lost. I created a main window in the designer and saved it and now I'm trying to use it.

main.cpp

#include <QApplication>
#include "MainWindow.h"

int main(int argc, char *argv[])
{
QApplication app(argc, argv);

MainWindow *mainW = new MainWindow();
mainW->show();

return app.exec();
}

MainWindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QDialog>
#include <ui_MainWindow.h>

class MainWindow : public QDialog, public Ui::MainWindow
{
Q_OBJECT

public:
MainWindow(QWidget *parent = 0);
}

MainWindow.cpp

#include "MainWindow.h"

MainWindow::MainWindow(QWidget *parent )
: QDialog(parent)
{
setupUi(this);
}

The error that I get is:
MainWindow.cpp: In constructor 'MainWindow::MainWindow(QWidget*)':
MainWindow.cpp:26: error: no matching function for call to 'MainWindow::setupUi(MainWindow* const)'
Ui/ui_MainWindow.h:52: note: candidates are: void Ui_MainWindow::setupUi(QMainWindow*)

So I know my problem is the "setupUi(this);" What the hell does it want? I'm lost.

Thanks,
Paul

wysota
23rd November 2006, 07:03
Your ui form is based on QMainWindow but you're trying to use QDialog as the base class for it. The base classes have to match.

sunil.thaha
23rd November 2006, 07:32
Instead of inheriting from QDialog, try inheriting from QMainWindow