Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [partial solved] How emit SIGNAL

[partial solved] How emit SIGNAL

Scheduled Pinned Locked Moved General and Desktop
signaleventyoctopuce
7 Posts 3 Posters 2.4k Views
  • 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.
  • F Offline
    F Offline
    Franckynos
    wrote on 8 Oct 2015, 10:07 last edited by Franckynos 10 Aug 2015, 15:46
    #1

    Hi,

    I have a problem with my code.
    I use some card "Yoctopuce" write in c++.
    The library work with callback.
    I want emit signal when callback arrived.
    For define a callback i do this :

    YVoltage*  volt = YVoltage::FindVoltage(target + ".voltage");
    volt->registerValueCallback(mycall);
    
    void mycall(YSensor *volt, const string& value)
    {
        qDebug() << "plop" << volt->get_module()->get_serialNumber().c_str() <<value.c_str();
        //emit COCO();
    }
    

    but my function call (callback) is not member of my Qt class so I can't emit signals... who can I do this ?

    The parameters of registerValueCallback is (virtual int registerValueCallback(YVoltageValueCallback callback);)
    and YVoltageValueCallback is (typedef void (*YVoltageValueCallback)(YVoltage *func, const string& functionValue);)

    Someone can help me ?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 8 Oct 2015, 10:33 last edited by
      #2

      If I understand you right you already have a class derived from QObject. In this case you can use an instance of that class to emit a signal:

      void mycall(YSensor *volt, const string& value)
      {
          myClassInstance.foundVoltage();
      }
      
      void MyClass::foundVoltage()
      {
         emit mySignal();
      }
      

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

      1 Reply Last reply
      0
      • F Offline
        F Offline
        Franckynos
        wrote on 8 Oct 2015, 10:53 last edited by
        #3

        @jsulm said:

        myClassInstance

        not really I have no access to QObject or Q ... something in mycall, it's a "volatile" function.

        it's a callback so pointer of function.

        If I try to insert mycall in My class the library yoctopuce says:

        Impossible to convert Motor::* in YVoltageValueCallback

        volt->registerValueCallback(&Motor::mycall)
        
        J 1 Reply Last reply 8 Oct 2015, 12:57
        0
        • F Franckynos
          8 Oct 2015, 10:53

          @jsulm said:

          myClassInstance

          not really I have no access to QObject or Q ... something in mycall, it's a "volatile" function.

          it's a callback so pointer of function.

          If I try to insert mycall in My class the library yoctopuce says:

          Impossible to convert Motor::* in YVoltageValueCallback

          volt->registerValueCallback(&Motor::mycall)
          
          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 8 Oct 2015, 12:57 last edited by
          #4

          @Franckynos But in your function you can call any public methods of any class instance, you just need access to such an instance.

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

          F 2 Replies Last reply 8 Oct 2015, 13:23
          0
          • H Offline
            H Offline
            Hamed.Masafi
            wrote on 8 Oct 2015, 13:04 last edited by
            #5

            You can implement observer pattern.

            Remote object sharing (OO RPC)
            http://forum.qt.io/topic/60680/remote-object-sharing-oo-rpc-solved

            Advanced, Powerful and easy to use ORM for Qt5
            https://forum.qt.io/topic/67417/advanced-powerful-and-easy-to-use-orm-for-qt5

            1 Reply Last reply
            0
            • J jsulm
              8 Oct 2015, 12:57

              @Franckynos But in your function you can call any public methods of any class instance, you just need access to such an instance.

              F Offline
              F Offline
              Franckynos
              wrote on 8 Oct 2015, 13:23 last edited by
              #6

              @jsulm

              but the function is static but I'll tried to do something with pointer...

              1 Reply Last reply
              0
              • J jsulm
                8 Oct 2015, 12:57

                @Franckynos But in your function you can call any public methods of any class instance, you just need access to such an instance.

                F Offline
                F Offline
                Franckynos
                wrote on 8 Oct 2015, 13:37 last edited by
                #7

                @jsulm I have declared a pointer to my class to have access at the instance and it works! I found this methode not really good with static member but for the moment I have juste this solution.

                1 Reply Last reply
                0

                1/7

                8 Oct 2015, 10:07

                • Login

                • Login or register to search.
                1 out of 7
                • First post
                  1/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved