[Solved] Widgets not showing 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.



  • Hi,
    Did you set a layout on the dialog?? When no layout is set, all widgets will be placed (normally) in your top left corner of the parent widget. If you used QtDesigner it shouldn't be hard to do that. Did you also set the title etc in that designer form? Are you trying to use the dialog from a non QObject derived class? That way it can't have a parent and to display that on the correct position is not easily controlled. Post some class code and we're able to help you some more.
    Greetz



  • 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:

    @Ui::Dialog ui_d1;
    Dialog D1;
    ui_d1.setupUi(&D1);@

    @ if (D1.exec() == QDialog::Accepted)
    {

            Temp1 = D1.lineEdit->text();
    
            // Some following code
    

    }
    @

    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?



  • Found the problem.

    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;


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.