Access MainWindow controls from callback function



  • Hello,

    What is the best way to access MainWindow controls from callback function?

    For example I have callback function that was initialized by passing to .so library function parameter. *.so library is going to update progress status by using it.

    cb(int value)
    {
    
    }
    

    And I need to show value in text box of tbCommandReturnMessage. Can I somehow use signals and slots for this purpose?


  • Moderators

    @column You can use a singleton for this:

    class CallbackHandler: public QObject
    {
    signals:
        void someSignal(int);
    
    public:
        static CallbackHandler* instance() {
            static CallbackHandler* i = new CallbackHandler();
            return i;
        }
        void doSomething(int value) { emit someSignal(value); }
    };
    
    void cb(int value)
    {
        CallbackHandler::instance()->doSomething(value);
    }
    

  • Lifetime Qt Champion

    Hi,

    What is the signature of that callback ?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.