Results 1 to 5 of 5

Thread: Widgets not displaying on dialog box

  1. #1
    Join Date
    Feb 2013
    Posts
    65
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Widgets not displaying on dialog box

    I'm using a dialog box created in Qt Creator, class called Ui_DIalog. The dialog displays when I use it but the window title is just the name of my project, not the designed window title, and the widgets don't show: 6 labels, a lineEdit , and OK and cancel buttons. None of them display. The dialog is called within another class member procedure. The code is:


    Ui_Dialog D1;

    if(D1.exec() == QDialog::Accepted)
    { // some code }

    Any help with this would be appreciated. Thanks in advance.

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    509
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Widgets not displaying on dialog box

    Hi, you don't use the classes created by Qt Designer and uic directly. Instead you use them as a member or base class of your own widget class.
    The widgets will be shown after a call to setupUi() method.

    Ginsengelf

    edit: maybe this helps: http://qt-project.org/doc/qt-4.8/des...a-ui-file.html

  3. #3
    Join Date
    Feb 2013
    Posts
    65
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default [Solved] Widgets not displaying on dialog box

    I got the widgets to display. When I originally created the dialog in the designer, the dialog was was named by Object

    as Dialog. But no dialog.h was created. So I used uic in the Qt bin folder to create it. In the resulting dialog.h the

    class is called Ui_Dialog, with a namespace declaration at the bottom of it called Ui, specifying the Dialog class.

    So in my class .cpp that's calling the dialog, I added:

    using namespace Ui;

    Then in my class calling procedure I used the following code:
    Qt Code:
    1. Ui::Dialog ui_d1;
    2. Dialog D1;
    3. ui_d1.setupUi(&D1);
    4.  
    5. if(D1.exec() == QDialog::Accepted)
    6. {
    7.  
    8. Temp1 = D1.lineEdit->text();
    9.  
    10. // Some following code
    11.  
    12. }
    To copy to clipboard, switch view to plain text mode 
    But now the program crashes when using the text() function to return the text of the lineEdit. Temp1 is a QString

    declared variable and the program runs when I use a valid value of "2", commenting out the lineEdit->text() line.

    Any ideas what could be causing that?

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QLineEdit text() method causing dialog and program to crash

    this is a very uncommon way to apply the generated code to a dialog.

    Usually the generated code (Ui:ialog in your case) is instantiated in the constructor of the class (in your case Dialog) and then setupUi is called with "this".

    You problem is very likely that you have a lineEdit member in your Dialog class that is not initialized, maybe not even created.
    You see the UI element of Ui:ialog, but you are not accessing them in the if's body.

    Proper encapsulation can easily avoid those inconsistencies.

    Cheers,
    _

  5. #5
    Join Date
    Feb 2013
    Posts
    65
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QLineEdit text() method causing dialog and program to crash

    Just adding

    setupUI (this);

    to the dialog constructor fixed the problem, along with just using the following declaration in my class procedure:

    Dialog *D1 = new Dialog;

    Thanks for the replies.

Similar Threads

  1. tree view displaying widgets as items
    By paksas in forum Qt Programming
    Replies: 9
    Last Post: 28th January 2013, 13:58
  2. Replies: 1
    Last Post: 12th May 2011, 22:41
  3. Replies: 3
    Last Post: 17th May 2007, 13:50
  4. Displaying external dialog
    By jlyanez in forum Qt Programming
    Replies: 1
    Last Post: 21st February 2007, 20:04

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.