Results 1 to 3 of 3

Thread: inter widget communication

  1. #1
    Join Date
    Sep 2007
    Posts
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default inter widget communication

    Hi All,

    I have created three classes, of which one is inherited from QMainWindow and other two are inherited from QWidget. I have designed the GUI using QT Designer. The classes are as follows.

    MainWindow - inherited from QMainWindow.
    wrapperSDKParams - inherieted from QWidget
    wrapperLog - inherieted from QWidget

    Now inside MainWindow class I have created objects of the rest of the two. Now I want to send a message from object of wrapperSDKparams to wrapperLog. How can I do it ? Please help me.

    Qt Code:
    1. class MainWindow : public QMainWindow
    2. {
    3. Q_OBJECT
    4.  
    5. private:
    6. QWorkspace *workspace;
    7. QMenu *initMenu;
    8. QMenu *viewMenu;
    9. QAction *initAction;
    10. QAction *viewAction;
    11. wrapperLog *log;
    12.  
    13. public:
    14. MainWindow();
    15. void AddActions();
    16. void AddMenus();
    17. void initErrors();
    18. //void addError(QString *error);
    19.  
    20. public slots:
    21. void displayForm();
    22. void displayErrors();
    23. };
    24.  
    25. class wrapperSDKParams : public QWidget, private Ui::sdk_params
    26. {
    27. Q_OBJECT
    28.  
    29. private:
    30. unsigned int debug_flag;
    31.  
    32. public:
    33. wrapperSDKParams(QWidget *parent = 0);
    34. void setDefault();
    35. void updateDebugFlag();
    36.  
    37. public slots:
    38. void setDefaultValues();
    39. void enableGroupBox();
    40. void start_SDK();
    41. };
    42.  
    43. class wrapperLog : public QWidget, private Ui::frmLog
    44. {
    45. Q_OBJECT
    46.  
    47. public:
    48. wrapperLog(QWidget *parent = 0);
    49. void append(QString error);
    50. };
    To copy to clipboard, switch view to plain text mode 

    I want to call append from wrapperSDKParams.
    Last edited by wysota; 14th November 2007 at 10:00. Reason: missing [code] tags

  2. #2
    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: inter widget communication

    Make append() a slot, create a signal carrying a QString in wrapperSDKParams and connect() them from MainWindow constructor.

    Qt Code:
    1. MainWindow::MainWindow() : QMainWindow(){
    2. //...
    3. log = new wrapperLog(this);
    4. sdk = new wrapperSDKParams(this);
    5. //...
    6. connect(sdk, SIGNAL(message(QString)), log, SLOT(append(QString)));
    7. //...
    8. }
    To copy to clipboard, switch view to plain text mode 

    Then emit the signal each time when you want append() called.

  3. #3
    Join Date
    Sep 2007
    Posts
    17
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: inter widget communication

    Thanks a lot Mr. Wysota. It helped me so much. Now the program is working as I expected.

    Thanks again,
    Venkata Subba Rao A.

Similar Threads

  1. Replies: 3
    Last Post: 17th October 2007, 12:52
  2. transparent background of the main widget
    By nagpalma in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2007, 17:52
  3. Controlling which widget on top layer?
    By JonathanForQT4 in forum Qt Programming
    Replies: 6
    Last Post: 22nd March 2007, 14:27
  4. Inter Process Communication
    By yellowmat in forum Qt Programming
    Replies: 3
    Last Post: 20th July 2006, 11:44
  5. [Qt 4.1.0] Split a widget on demand
    By Townk in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2006, 14:16

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.