Results 1 to 9 of 9

Thread: Two windows in the same main

  1. #1
    Join Date
    Sep 2010
    Posts
    12
    Qt products
    Platforms
    Unix/X11

    Default Two windows in the same main

    Hi!
    Sorry if this is a dumb question but I have no past experience with threads and/or network communication.
    I'm making a simple tcp communication: I have a sender and I have a receiver.
    For now I have 2 different project in QtCreator, one for the sender and one for the receiver. I'm testing the network communication in this way: I open the receiver and then and I open the sender.
    But I'd like to have a single progect called SenderReceiverTest that open 2 window, one for the receiver, one for the sender, in the same QtCreator project.
    First question: Is this single-project stuff a good idea?

    Then...
    If i have something like this:

    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "windowsender.h"
    3. #include "windowreceiver.h"
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7.  
    8. QApplication a(argc, argv);
    9. QApplication a(argc, argv);
    10.  
    11. WindowReceiver r;
    12. r.show();
    13. WindowSender s;
    14. s.show();
    15.  
    16. QObject::connect(&r, SIGNAL(windowClosed()), // custom virtual void closeEvent(QCloseEvent *e)
    17. &s, SLOT(close()));
    18. QObject::connect(&s, SIGNAL(windowClosed()), // custom virtual void closeEvent(QCloseEvent *e)
    19. &r, SLOT(close()));
    20.  
    21. return a.exec();
    22. }
    To copy to clipboard, switch view to plain text mode 

    Second question:
    The two window are in the same thread, aren't they? I'd like to have the two windows in different thread for testing real async communication.. and for that I should have two dirrefent thread.. right? How can I do this?

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Two windows in the same main

    You can't. Qt GUI objects can exist only in main thread.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Two windows in the same main

    For testing asynchronous communication you don't need threads.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Sep 2010
    Posts
    12
    Qt products
    Platforms
    Unix/X11

    Default Re: Two windows in the same main

    thank you for the answer.

    so the way i'm handling it now (two window.show in the same main) is a right way?
    is there a better way?

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Two windows in the same main

    It's ok but don't create two instances of QApplication. One is enough. Your current code would not even compile
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Sep 2010
    Posts
    12
    Qt products
    Platforms
    Unix/X11

    Default Re: Two windows in the same main

    Ah yeah sorry I have done some cut and paste for deleting comments and renaming the objects and there was a mistake.. : )

    So it is ok, I can test how many TCP package can be sent for a second and stuffs like this, good, thank you!

    One more question:
    what happens if I use moveToThread methods on a QWidget subclass?

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Two windows in the same main

    Most likely - BOOM!
    Less likely, a warning and a no-op.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Sep 2010
    Posts
    12
    Qt products
    Platforms
    Unix/X11

    Default Re: Two windows in the same main


    sorry?

    boom could mean runtime crash but.. no-op?

    anyway thank you for the answer i have understand i don't have to do it.

  9. #9
    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: Two windows in the same main

    Yes, boom refers to crashing
    no-op is short for "no operation", a term using in computer science to say that an instruction will actually not do anything.
    Like an empty method

    Cheers,
    _

Similar Threads

  1. Dialog box executed from main windows does not work ...
    By marco.stanzani in forum Qt Programming
    Replies: 0
    Last Post: 17th October 2011, 21:33
  2. How to close two main windows at a time
    By soumya in forum Qt Programming
    Replies: 7
    Last Post: 4th February 2010, 16:12
  3. How to show two main windows?
    By Althor in forum Newbie
    Replies: 4
    Last Post: 13th October 2008, 08:30
  4. Replies: 11
    Last Post: 11th August 2008, 09:14
  5. How to close all windows that were created in main()?
    By Mister_Crac in forum Qt Programming
    Replies: 6
    Last Post: 13th November 2006, 10:57

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.