Results 1 to 4 of 4

Thread: Using UI class from Designer?

  1. #1
    Join Date
    Aug 2010
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Question Using UI class from Designer?

    Hello
    I have finished a qt tutorial from another site. Everything runs fine except the GUI i made in QT Designer does not show up. All tutorials I can find on the subject implements it the same way.

    So to summon it up. I only get a blank window when I run my project.

    Main.cpp
    Qt Code:
    1. #include <QtCore/QCoreApplication>
    2. #include "TempForm.h"
    3. #include "Window.h"
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication a(argc, argv);
    8.  
    9. Window mWindow;
    10. mWindow.resize(800,600);
    11. mWindow.show();
    12.  
    13. return a.exec();
    14. }
    15. #endif
    To copy to clipboard, switch view to plain text mode 

    Window.h
    Qt Code:
    1. #ifndef WINDOW_H
    2. #define WINDOW_H
    3.  
    4. #include <QtOpenGl/QGLWidget>
    5. #include <QtGui>
    6. #include "TempForm.h"
    7.  
    8. class Window : public QWidget , private Ui::MainWindow //MainWindow is the class name from QT Designer header file (TempForm.h)
    9. {
    10. public:
    11. Window(QWidget *parent = 0);
    12. ~Window();
    13. };
    14. #endif
    To copy to clipboard, switch view to plain text mode 

    Window.cpp
    Qt Code:
    1. #include <QtGui/QMouseEvent>
    2. #include "Window.h"
    3.  
    4. Window::Window(QWidget *parent)
    5. {
    6. setupUi(&(QMainWindow)this); // this sets up GUI
    7. }
    8. Window::~Window()
    9. {
    10.  
    11. }
    To copy to clipboard, switch view to plain text mode 

    If I manually call each guielemts show function my application crash.

    Any suggestions?

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Using UI class from Designer?

    Try this:
    Qt Code:
    1. #include <QtGui/QMouseEvent>
    2. #include "Window.h"
    3.  
    4. Window::Window(QWidget *parent)
    5. {
    6. setupUi(this); // this sets up GUI
    7. }
    To copy to clipboard, switch view to plain text mode 

    LE: And you include TempForm.h and private inherit from Ui::MainWindow? something is not right in there (you should public inherit the class that UIC created for you)

    Here is the official guide that is presenting you all you need to know on how to integrate ui file in your c++ code.
    Last edited by Zlatomir; 21st September 2010 at 11:11.

  3. #3
    Join Date
    Aug 2010
    Posts
    4
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Using UI class from Designer?

    Thanks for looking over it.

    Yeah private inherit was not intended but dident solw the problem either.

    Using this was giving an error witch is not strange. Thats why I was casting.
    Qt Code:
    1. setupUi(this); // this sets up GUI
    To copy to clipboard, switch view to plain text mode 

    By inherit from QMainWindow rather than QWidget fixed the problem for me.

  4. #4
    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: Using UI class from Designer?

    Quote Originally Posted by miivers View Post
    I have finished a qt tutorial from another site. Everything runs fine except the GUI i made in QT Designer does not show up. All tutorials I can find on the subject implements it the same way.
    Maybe you shouldn't take tutorials from those "other sites"
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. accessing static member variables of one class in another class
    By jasonknight in forum General Programming
    Replies: 5
    Last Post: 6th September 2010, 15:53
  2. What is class 'Line' in designer?
    By Kumosan in forum Qt Programming
    Replies: 2
    Last Post: 3rd April 2009, 11:12
  3. Replies: 0
    Last Post: 3rd January 2009, 06:26
  4. Replies: 3
    Last Post: 27th December 2008, 20:34
  5. Replies: 3
    Last Post: 16th May 2007, 12:07

Tags for this Thread

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.