Results 1 to 4 of 4

Thread: QWidget from ui

  1. #1
    Join Date
    Dec 2008
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QWidget from ui

    Hello everyone.

    In the books I have reading regarding qt4 the designer programm was used to create dialogs. But this time I thought the best solution was to create the ui form in designer, describe it as widget and after - use such widget as main windget in mainwindow.

    I was looking in google form a lolution. I coold find some information regarding it, but it didn't work well.

    What I did:

    there is the ui file "mainwidget.h" as qwidget.

    For the first try all I want is to see it's working:

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

    and mainwidget.cpp
    Qt Code:
    1. #include "mainwidget.h"
    2.  
    3. MainWidget::MainWidget(QWidget *parent) : QWidget(parent)
    4. {
    5.  
    6. }
    To copy to clipboard, switch view to plain text mode 

    Then i create the main.cpp:
    Qt Code:
    1. #include <QApplication>
    2. #include "mainwidget.h"
    3.  
    4. int main(int argc, char **argv){
    5. QApplication app(argc, argv);
    6. MainWidget wgt;
    7. wgt.show();
    8. return app.exec();
    9. }
    To copy to clipboard, switch view to plain text mode 

    Then I create the .pro file, add the RESOURCES line, copy the icon's folder.
    It compiles with no errors. It even does launch, but I cannot see anything - just empty window of the desired size.

    Is there anything I am doing wrong in here?

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QWidget from ui

    try this
    Qt Code:
    1. #include "mainwidget.h"
    2.  
    3. MainWidget::MainWidget(QWidget *parent) : QWidget(parent)
    4. {
    5. setupUi(this);
    6. }
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Dec 2008
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QWidget from ui

    that is the designer screenshot:

    and that is what i see after execution:

  4. #4
    Join Date
    Dec 2008
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QWidget from ui

    spirit

    Thanks a lot!! That's done!!

Similar Threads

  1. Replies: 0
    Last Post: 11th November 2008, 15:36
  2. Dynamic updates of a QWidget in a QScrollArea
    By plamkata in forum Qt Programming
    Replies: 2
    Last Post: 20th July 2008, 23:45
  3. Error in put one QWidget in another QWidget
    By xjtu in forum Qt Programming
    Replies: 1
    Last Post: 19th April 2008, 16:05
  4. Dynamic widget not displayed upon Qwidget
    By ashukla in forum Qt Programming
    Replies: 5
    Last Post: 17th December 2007, 11:11
  5. Replies: 3
    Last Post: 8th March 2007, 14:54

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
  •  
Qt is a trademark of The Qt Company.