Results 1 to 3 of 3

Thread: How do I use a mainwindow .ui file?

  1. #1
    Join Date
    Nov 2006
    Posts
    86
    Thanks
    6
    Thanked 14 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default How do I use a mainwindow .ui file?

    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
    Qt Code:
    1. #include <QApplication>
    2. #include "MainWindow.h"
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication app(argc, argv);
    7.  
    8. MainWindow *mainW = new MainWindow();
    9. mainW->show();
    10.  
    11. return app.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 

    MainWindow.h
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QDialog>
    5. #include <ui_MainWindow.h>
    6.  
    7. class MainWindow : public QDialog, public Ui::MainWindow
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. MainWindow(QWidget *parent = 0);
    13. }
    To copy to clipboard, switch view to plain text mode 

    MainWindow.cpp
    Qt Code:
    1. #include "MainWindow.h"
    2.  
    3. MainWindow::MainWindow(QWidget *parent )
    4. : QDialog(parent)
    5. {
    6. setupUi(this);
    7. }
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How do I use a mainwindow .ui file?

    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.

  3. #3
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How do I use a mainwindow .ui file?

    Instead of inheriting from QDialog, try inheriting from QMainWindow
    We can't solve problems by using the same kind of thinking we used when we created them

Similar Threads

  1. Draging a non-existing file to the Windows Desktop
    By klaus1111 in forum Qt Programming
    Replies: 13
    Last Post: 20th September 2007, 11:47
  2. .ui file name and classname
    By Rekha in forum Newbie
    Replies: 3
    Last Post: 12th August 2006, 01:53
  3. SQLite-DB in a qrc file
    By Lykurg in forum Qt Programming
    Replies: 5
    Last Post: 31st July 2006, 19:24
  4. QHttp GET File & Password
    By patrik08 in forum Qt Programming
    Replies: 4
    Last Post: 11th June 2006, 13:04
  5. dialog box
    By Bahar in forum Qt Programming
    Replies: 3
    Last Post: 31st January 2006, 14:52

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.