Results 1 to 20 of 29

Thread: Need 2 widgets without a parent to comunicate

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #20
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Need 2 widgets without a parent to comunicate

    I don't think we can help you if you show us code that does something different than the one you are actually using...

    If the two windows are never shown together maybe you should use a QStackedWidget instead of two widgets?

    Anyway... if I wanted to have a mechanism for switching windows, I'd do it more or less like this:
    Qt Code:
    1. class Dispatcher : public QObject {
    2. Q_OBJECT
    3. public:
    4. void addWindow(QWidget *win) {
    5. m_windows << win;
    6. if(m_current == -1) {
    7. setWindow(0);
    8. }
    9. }
    10. public slots:
    11. void next() {
    12. setWindow(m_current+1 % m_windows.count());
    13. }
    14. void prev() {
    15. setWindow(m_current-1 % m_windows.count());
    16. }
    17. void setWindow(int which) {
    18. if(m_current == which) return;
    19. if(m_current!=-1) {
    20. m_windows.at(m_current)->hide();
    21. }
    22. m_current = which;
    23. m_windows.at(m_current)->show();
    24. qApp->processEvents(); // optionally force event processing (don't unless sure it's required)
    25. }
    26. private:
    27. QList<QWidget *> m_windows;
    28. int current = -1;
    29. };
    To copy to clipboard, switch view to plain text mode 

    Then it's just a matter of connecting a signal to one of the slots defined in the dispatcher.
    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.


  2. The following user says thank you to wysota for this useful post:

    boblatino (26th July 2010)

Similar Threads

  1. Replies: 7
    Last Post: 12th January 2011, 22:01
  2. Replies: 1
    Last Post: 22nd April 2010, 14:34
  3. Replies: 2
    Last Post: 22nd April 2010, 11:44
  4. Replies: 3
    Last Post: 29th May 2008, 13:50
  5. initialize child widgets within parent?
    By ucomesdag in forum Newbie
    Replies: 6
    Last Post: 6th June 2006, 08:11

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.