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
Forum Updated to NodeBB v4.3 + New Features

[partial solved] How emit SIGNAL

Scheduled Pinned Locked Moved General and Desktop
signaleventyoctopuce
7 Posts 3 Posters 2.4k Views 1 Watching
  • 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.
  • FranckynosF Offline
    FranckynosF Offline
    Franckynos
    wrote on last edited by Franckynos
    #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
    • jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on 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
      • FranckynosF Offline
        FranckynosF Offline
        Franckynos
        wrote on 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)
        
        jsulmJ 1 Reply Last reply
        0
        • FranckynosF Franckynos

          @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)
          
          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on 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

          FranckynosF 2 Replies Last reply
          0
          • Hamed.MasafiH Offline
            Hamed.MasafiH Offline
            Hamed.Masafi
            wrote on 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
            • jsulmJ jsulm

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

              FranckynosF Offline
              FranckynosF Offline
              Franckynos
              wrote on last edited by
              #6

              @jsulm

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

              1 Reply Last reply
              0
              • jsulmJ jsulm

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

                FranckynosF Offline
                FranckynosF Offline
                Franckynos
                wrote on 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

                • Login

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