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. Dialog does not display when main window loads

Dialog does not display when main window loads

Scheduled Pinned Locked Moved General and Desktop
10 Posts 4 Posters 5.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.
  • K Offline
    K Offline
    kalster
    wrote on last edited by
    #1

    I am new to programming in the mainwindow.cpp for the qt designer mainwindow.ui file. In the mainwindow.cpp file, the code completion does not work for the dialog. ui->dialog does nothing when typed in at the MainWindow::MainWindow(QWidget *parent) :.

    I am trying to display the dialog.ui as a child of mainwindow.ui. I would like the dialog to load in front of the mainwindow as soon as the program loads. can i have a working example that i could type into the mainwindow.cpp please.

    mainwindow.cpp
    @#include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include "dialog.h"
    #include "ui_dialog.h"

    Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
    {
    ui->setupUi(this);
    }

    Dialog::~Dialog()
    {
    delete ui;
    }

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }@

    main.cpp
    @#include <QtGui/QApplication>
    #include "mainwindow.h"

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec(&#41;;
    

    }
    @

    1 Reply Last reply
    0
    • C Offline
      C Offline
      chernetsov0
      wrote on last edited by
      #2

      You actually need to change everything for this to work. So try some reading of manuals, I suppose.

      Programmer is an organism that can turn caffeine into code.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        giesbert
        wrote on last edited by
        #3

        Are you looking for a Splash screen?
        Showing a dialog while something other creates and displays is not possible. You can show a mode less dialog, but to get this, you need a running event loop. The main window is typically created before the event loop runs.

        Nokia Certified Qt Specialist.
        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kalster
          wrote on last edited by
          #4

          yes, i am trying for a splash screen. I would like it to load in front of the main form as soon as the program loads. are you saying that is not possible without an event loop?

          I might be able to get it running but i need to know how to set the splash screen form as the child of the mainwindow form and coded for the mainwindow.cpp file. Can i have help in this please or will i still need an event loop?

          1 Reply Last reply
          0
          • G Offline
            G Offline
            giesbert
            wrote on last edited by
            #5

            If you need a splash screen use QSplashScreen.
            But it will be a top level window and not part of the main window.

            If you want to show the main window first and then load your stuff, use a single shot timer and do it after displaying the main window.

            Nokia Certified Qt Specialist.
            Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

            1 Reply Last reply
            0
            • EddyE Offline
              EddyE Offline
              Eddy
              wrote on last edited by
              #6

              There is a splash screen example in chapter 3 of the official Qt book, which you can get "here":http://www.qtrac.eu/C++-GUI-Programming-with-Qt-4-1st-ed.zip.

              Qt Certified Specialist
              www.edalsolutions.be

              1 Reply Last reply
              0
              • G Offline
                G Offline
                giesbert
                wrote on last edited by
                #7

                You can also look to the "docs of QSplashScreen":http://doc.qt.nokia.com/4.7/qsplashscreen.html#details

                Nokia Certified Qt Specialist.
                Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  kalster
                  wrote on last edited by
                  #8

                  thank you Gerolf. I will read the QSplashScreen doc.

                  I managed to get the Dialog form loaded, but the Dialog loaded behind the MainWindow. Is this because I need that event loop? Also, the programs loads up as if I have two programs. Maybe because I did not set the Dialog as the child of the parent? Could I have an example on how to set the child up. thank you

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    giesbert
                    wrote on last edited by
                    #9

                    [quote author="Eddy" date="1312179551"]There is a splash screen example in chapter 3 of the official Qt book, which you can get "here":http://www.qtrac.eu/C++-GUI-Programming-with-Qt-4-1st-ed.zip.[/quote]

                    You should read a bit more introduction to Qt. Parent child relations are an absolute basic thing and you will need it.

                    Nokia Certified Qt Specialist.
                    Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                    1 Reply Last reply
                    0
                    • K Offline
                      K Offline
                      kalster
                      wrote on last edited by
                      #10

                      thank you

                      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