Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Access MainWindow controls from callback function

    General and Desktop
    3
    3
    385
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C
      column last edited by

      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?

      jsulm 1 Reply Last reply Reply Quote 0
      • jsulm
        jsulm Lifetime Qt Champion @column last edited by

        @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);
        }
        

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • SGaist
          SGaist Lifetime Qt Champion last edited by

          Hi,

          What is the signature of that callback ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply Reply Quote 0
          • First post
            Last post