Results 1 to 12 of 12

Thread: How to send data from a static function of other Class to a MainWindow function?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 370 Times in 336 Posts

    Default Re: How to send data from a static function of other Class to a MainWindow function?

    It's an interesting interpretation, but I would make this in other way: make this object as a singleton
    Qt Code:
    1. class Global: public QObject
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. static Global *instance();
    7.  
    8. void send_name(const QString &color_name);
    9. ...
    10.  
    11. Q_SIGNALS:
    12. void send_color(const QString &color_name);
    13.  
    14. private:
    15. Q_DISABLE_COPY(Global);
    16. };
    17.  
    18. #define myGlobal Global::instance() //shortcut
    To copy to clipboard, switch view to plain text mode 

    Then
    Qt Code:
    1. ...
    2. connect(myGlobal, SIGNAL(send_color(const QString &)), SLOT(applyColor(const QString &)));
    3. ...
    4. myGlobal->send_name("lightgray");
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

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

    hakermania (4th September 2012)

Similar Threads

  1. Replies: 2
    Last Post: 19th July 2018, 06:38
  2. Replies: 4
    Last Post: 23rd August 2011, 21:53
  3. Replies: 1
    Last Post: 13th April 2011, 11:24
  4. Can you send a signal from a static callback function?
    By Eos Pengwern in forum Qt Programming
    Replies: 2
    Last Post: 12th August 2010, 13:47
  5. Replies: 3
    Last Post: 14th October 2008, 21:04

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.