Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Widgets not showing on dialog box
Forum Updated to NodeBB v4.3 + New Features

[Solved] Widgets not showing on dialog box

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    te777
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      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

      Greetz, Jeroen

      1 Reply Last reply
      0
      • T Offline
        T Offline
        te777
        wrote on last edited by
        #3

        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?

        1 Reply Last reply
        0
        • T Offline
          T Offline
          te777
          wrote on last edited by
          #4

          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;

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved