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. Multiple Widgets

Multiple Widgets

Scheduled Pinned Locked Moved General and Desktop
7 Posts 5 Posters 2.7k Views
  • 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.
  • Z Offline
    Z Offline
    zEp0
    wrote on last edited by
    #1

    Hello everyone,

    my Problem: I have two Widgets in my Projekt. How can I tell QT, which one he should run at first?

    Thank you!

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      To vague to answer with certainty. Are those 2 QMainWindows? Is one of them a dialog, message box or else?

      In general, in your main routine (int main()), you can show the first widget first, and then when it finishes (you can destroy it, or just hide) you can show the other one. There are also other ways to do it, but I can't really say anything more concrete before you give more details on your situation.

      (Z(:^

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        zEp0
        wrote on last edited by
        #3

        Thank you for your answer!

        Both Widgets are normal QWidgets..
        I don't know, how I could explain them more precise. I just created a Project with a normal QWidget and then I added the other Widget.

        Thank you!

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          qxoz
          wrote on last edited by
          #4

          If you create project by QtCreator wizzard so look at main.cpp file:
          @#include <QtGui/QApplication>
          #include "widget.h"

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

          return a.exec&#40;&#41;;
          

          }@
          in line 7 creation of Widget object and at line 8 its shows. Other widget you can show from this one.
          But if you tell as what you try to do then you can get more useful answer.

          1 Reply Last reply
          0
          • U Offline
            U Offline
            utcenter
            wrote on last edited by
            #5

            [quote author="zEp0" date="1360512318"] How can I tell QT, which one he should run at first?
            Thank you![/quote]

            It will be the one instantiated in your main() function. Widgets are like nesting dolls, you can put widgets inside widgets. So if your second widget needs to show from the first widget, all you need to do is put it in there, just like you would but a button, a check box or any other widget derived component. You can of course always show the second widget conditionally.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              Serenity
              wrote on last edited by
              #6

              It's not the best solution but it is one, because I don't know your exact usage of your application.

              Make your both QWidgets to QDialog (.i.e: "class A : public QWidget" to "class A : public QDialog" ) and then use the exec() function instead of show().
              Like:

              [code]int main(int argc, char *argv[])
              {
              QApplication a(argc, argv);
              WDialog1 w1;
              w1.exec();
              WDialog2 w2;
              w2.exec();

              return a.exec&#40;&#41;;
              

              }[/code]

              It will first start the w1 instance and when you close it, it will start the next instance (w2).

              1 Reply Last reply
              0
              • Z Offline
                Z Offline
                zEp0
                wrote on last edited by
                #7

                Thank you guys, I will try it!

                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