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. Acting on a QCamera object with an external function

Acting on a QCamera object with an external function

Scheduled Pinned Locked Moved Unsolved General and Desktop
qcameradll
15 Posts 3 Posters 4.0k 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.
  • jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #4

    It looks like you already linking against this library, so there is no need for

    QLibrary myLib("D:\\my\\path\\to\\X.dll");
    

    Well, then you cannot control the camera directly from these functions as they do not know anything about QCamera. You will have to write some glue code between those functions and the camera.

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

    1 Reply Last reply
    1
    • S Offline
      S Offline
      Suji
      wrote on last edited by Suji
      #5

      Hi again @jsulm !

      Yes, it was a lack of comprehension evidence :s

      So, I have to change this too no ? :

      void ParametersDialog::activateSetAutoWhiteBalance()
      {
         MyPrototype funcSetAutoWhiteBalance = (MyPrototype) myLib.resolve("X_SetAutoWhiteBalance");
          if (funcSetAutoWhiteBalance)
      
             funcSetAutoWhiteBalance(TRUE);
      }
      

      How ? Because if i try to just do funcSetAutoWhiteBalance(TRUE), compiler answer that it is not declared...Do I just have to declare it in my ParametersDialog.h ?

      "Well, then you cannot control the camera directly from these functions as they do not know anything about QCamera. You will have to write some glue code between those functions and the camera."
      Yes, @kshegunov said me the same thing. I'm a beginner, do you have some ideas in order to help me building this "glue code" ? :)

      Thanks a lot for your help, I know my ignorance is a bit irritating.

      kshegunovK 1 Reply Last reply
      0
      • S Suji

        Hi again @jsulm !

        Yes, it was a lack of comprehension evidence :s

        So, I have to change this too no ? :

        void ParametersDialog::activateSetAutoWhiteBalance()
        {
           MyPrototype funcSetAutoWhiteBalance = (MyPrototype) myLib.resolve("X_SetAutoWhiteBalance");
            if (funcSetAutoWhiteBalance)
        
               funcSetAutoWhiteBalance(TRUE);
        }
        

        How ? Because if i try to just do funcSetAutoWhiteBalance(TRUE), compiler answer that it is not declared...Do I just have to declare it in my ParametersDialog.h ?

        "Well, then you cannot control the camera directly from these functions as they do not know anything about QCamera. You will have to write some glue code between those functions and the camera."
        Yes, @kshegunov said me the same thing. I'm a beginner, do you have some ideas in order to help me building this "glue code" ? :)

        Thanks a lot for your help, I know my ignorance is a bit irritating.

        kshegunovK Offline
        kshegunovK Offline
        kshegunov
        Moderators
        wrote on last edited by kshegunov
        #6

        Hello @Suji,
        If you're doing linking in your project file, as shown in post #3, you shouldn't want to do this at all:

        (MyPrototype) myLib.resolve("X_SetAutoWhiteBalance");
        

        Just as @jsulm noted, the resolution of symbols will be done for you by the loader. You just use the functions declared in the vendor's header directly:

        void ParametersDialog::activateSetAutoWhiteBalance()
        {
            X_SetAutoWhiteBalance(true);
        }
        

        Yes, @kshegunov said me the same thing. I'm a beginner, do you have some ideas in order to help me building this "glue code" ? :)

        This is an entirely different problem. Your vendor library (judging from the previous thread) has no notion of objects, so to use it as you'd use QCamera you'd have to write your own class and manage everything that comes with it. That said, something like this:

        class MyCamera : public QCamera
        {
            // ...
        }
        

        or, a backend for the QCamera class, although I've not worked with the multimedia module so I don't know how that's done exactly. You could search in the documentation of the multimedia module and see if it actually provides a way to plug-in your own camera controllers. Unfortunately, I can't see a (base) class that'd be useful for this purpose.

        Kind regards.

        Read and abide by the Qt Code of Conduct

        1 Reply Last reply
        1
        • S Offline
          S Offline
          Suji
          wrote on last edited by Suji
          #7

          hi @kshegunov ;)

          Thank you for your answer! Oh, I understand the glue code logic better now.

          When i juste write :

          void ParametersDialog::activateSetAutoWhiteBalance()
          {
              X_SetAutoWhiteBalance(true);
          }
          

          A last question : The compiler say that X_SetAutoWhiteBalance is not defined in this scope. I have to define it in my ParametersDialog.h, into the class MyCamera : public QCamera for example, is it "normal" ?

          Thanks again !

          kshegunovK 1 Reply Last reply
          0
          • S Suji

            hi @kshegunov ;)

            Thank you for your answer! Oh, I understand the glue code logic better now.

            When i juste write :

            void ParametersDialog::activateSetAutoWhiteBalance()
            {
                X_SetAutoWhiteBalance(true);
            }
            

            A last question : The compiler say that X_SetAutoWhiteBalance is not defined in this scope. I have to define it in my ParametersDialog.h, into the class MyCamera : public QCamera for example, is it "normal" ?

            Thanks again !

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by kshegunov
            #8

            @Suji

            A last question : The compiler say that X_SetAutoWhiteBalance is not defined in this scope. I have to define it in my ParametersDialog.h, into the class MyCamera : public QCamera for example, is it "normal" ?

            Could you provide the full error you're getting? Can you check in the vendor's header whether that function is declared? - You'd expect to see something like (it may not be exactly as this, but similar):

            bool X_SetAutoWhiteBalance(bool);
            

            Kind regards.

            Read and abide by the Qt Code of Conduct

            1 Reply Last reply
            0
            • S Offline
              S Offline
              Suji
              wrote on last edited by
              #9

              The full error is :
              D:\path\ParametersDialog.cpp:158: error : 'funcSetAutoWhiteBalance' was not declared in this scope
              funcSetAutoWhiteBalance(TRUE);

              The vendor files are like this :

              //A.cpp
              #include <A.h>
              #include <B.h>
              pPluginGetAutoWhiteBalance	= (pfApiPluginGetAutoWhiteBalance)GetProcAddress(m_Plugin_HModule2, "X_GetAutoWhiteBalance");
              
              //A.h
              HMODULE	                        m_Plugin_HModule2;
              pfApiPluginSetAutoWhiteBalance	pPluginSetAutoWhiteBalance;
              
              //B.h
              typedef BOOL (*pfApiPluginSetAutoWhiteBalance) (bool );
              

              Is it everything needed ?

              kshegunovK 1 Reply Last reply
              0
              • S Suji

                The full error is :
                D:\path\ParametersDialog.cpp:158: error : 'funcSetAutoWhiteBalance' was not declared in this scope
                funcSetAutoWhiteBalance(TRUE);

                The vendor files are like this :

                //A.cpp
                #include <A.h>
                #include <B.h>
                pPluginGetAutoWhiteBalance	= (pfApiPluginGetAutoWhiteBalance)GetProcAddress(m_Plugin_HModule2, "X_GetAutoWhiteBalance");
                
                //A.h
                HMODULE	                        m_Plugin_HModule2;
                pfApiPluginSetAutoWhiteBalance	pPluginSetAutoWhiteBalance;
                
                //B.h
                typedef BOOL (*pfApiPluginSetAutoWhiteBalance) (bool );
                

                Is it everything needed ?

                kshegunovK Offline
                kshegunovK Offline
                kshegunov
                Moderators
                wrote on last edited by kshegunov
                #10

                @Suji
                Oh, man, this is terrible!
                Okay. I presume there are a number of those lines:

                typedef BOOL (*pfApiPluginSetAutoWhiteBalance) (bool );
                

                Create your own header, containing each of the functions' declarations by replacing the function pointer types with a nice usable name. It goes like this:
                For each:

                typedef BOOL (*pfApiPluginSetAutoWhiteBalance) (bool);
                

                You put in your header:

                BOOL X_SetAutoWhiteBalance(bool);
                

                This will create the declarations you need, also include windows.h on top (for all that uppercase defines). To use it, then include the header you've created, link the library (as you're doing) and use the functions. Only thing to watch out for is to wrap the declarations in your header in an extern "C".

                Suppose you have this:

                typedef BOOL (*pfApiPluginSetAutoWhiteBalance) (bool);
                typedef BOOL (*pfApiPluginSetZoomLevel) (int);
                

                You put it all in your header like this:

                #ifndef MY_EXTERNAL_LIBRARY_HEADER_H
                #define MY_EXTERNAL_LIBRARY_HEADER_H
                
                #include <windows.h>
                
                extern "C"
                {
                    BOOL X_SetAutoWhiteBalance(bool);
                    BOOL X_SetZoomLevel(int);
                }
                
                #endif // MY_EXTERNAL_LIBRARY_HEADER_H
                

                You won't be needing to do this tedious exercise for every typedef in the vendor's header, but only for the functions you'll be using.
                Then in your source you can use like this (supposedly your newly created header is named "myexternallibheader.h"):

                #include "myexternallibheader.h"
                // DO NOT INCLUDE THE VENDOR'S HEADER, ONLY YOUR OWN!
                
                // ... more code ...
                
                void ParametersDialog::activateSetAutoWhiteBalance()
                {
                    X_SetAutoWhiteBalance(true);
                }
                

                Kind regards.

                Read and abide by the Qt Code of Conduct

                S 1 Reply Last reply
                1
                • S Offline
                  S Offline
                  Suji
                  wrote on last edited by
                  #11

                  It's all very clear ! Let's go ! I'll give you news about it ;) Thanks a lot !

                  kshegunovK 1 Reply Last reply
                  0
                  • S Suji

                    It's all very clear ! Let's go ! I'll give you news about it ;) Thanks a lot !

                    kshegunovK Offline
                    kshegunovK Offline
                    kshegunov
                    Moderators
                    wrote on last edited by kshegunov
                    #12

                    @Suji

                    ALTERNATIVELY

                    Include the vendor's header and use the functions as they're resolved at runtime (quite suspiciously if I may add), like this:

                    #include <vendorheader.h>
                    
                    // ... more code ...
                    
                    void ParametersDialog::activateSetAutoWhiteBalance()
                    {
                         pPluginGetAutoWhiteBalance(true);
                    }
                    

                    But if you choose this approach, do not link the library in your project file:

                    LIBS +=  -lExternalLibrary #< REMOVE THIS LINE IN THE .pro
                    

                    Note: However, this may lead to more problems, as you'd need to notify qmake to build the source file that resolves the symbols as well.

                    Kind regards.

                    Read and abide by the Qt Code of Conduct

                    1 Reply Last reply
                    1
                    • S Offline
                      S Offline
                      Suji
                      wrote on last edited by
                      #13

                      I'll try the first one firstly, seems to be a cleaner option, and I prefer to master all the code. :)

                      1 Reply Last reply
                      1
                      • kshegunovK kshegunov

                        @Suji
                        Oh, man, this is terrible!
                        Okay. I presume there are a number of those lines:

                        typedef BOOL (*pfApiPluginSetAutoWhiteBalance) (bool );
                        

                        Create your own header, containing each of the functions' declarations by replacing the function pointer types with a nice usable name. It goes like this:
                        For each:

                        typedef BOOL (*pfApiPluginSetAutoWhiteBalance) (bool);
                        

                        You put in your header:

                        BOOL X_SetAutoWhiteBalance(bool);
                        

                        This will create the declarations you need, also include windows.h on top (for all that uppercase defines). To use it, then include the header you've created, link the library (as you're doing) and use the functions. Only thing to watch out for is to wrap the declarations in your header in an extern "C".

                        Suppose you have this:

                        typedef BOOL (*pfApiPluginSetAutoWhiteBalance) (bool);
                        typedef BOOL (*pfApiPluginSetZoomLevel) (int);
                        

                        You put it all in your header like this:

                        #ifndef MY_EXTERNAL_LIBRARY_HEADER_H
                        #define MY_EXTERNAL_LIBRARY_HEADER_H
                        
                        #include <windows.h>
                        
                        extern "C"
                        {
                            BOOL X_SetAutoWhiteBalance(bool);
                            BOOL X_SetZoomLevel(int);
                        }
                        
                        #endif // MY_EXTERNAL_LIBRARY_HEADER_H
                        

                        You won't be needing to do this tedious exercise for every typedef in the vendor's header, but only for the functions you'll be using.
                        Then in your source you can use like this (supposedly your newly created header is named "myexternallibheader.h"):

                        #include "myexternallibheader.h"
                        // DO NOT INCLUDE THE VENDOR'S HEADER, ONLY YOUR OWN!
                        
                        // ... more code ...
                        
                        void ParametersDialog::activateSetAutoWhiteBalance()
                        {
                            X_SetAutoWhiteBalance(true);
                        }
                        

                        Kind regards.

                        S Offline
                        S Offline
                        Suji
                        wrote on last edited by Suji
                        #14

                        The first option work very well, thanks a lot !!

                        Thanks again @kshegunov !

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          Suji
                          wrote on last edited by
                          #15

                          Well, the first goal is not resolved, I still have to connect my extern functions with my QCamera object. I'll try to change the approach, throwing the QCamera object, and use QMediaService (tanks for the idea @kshegunov). If someone has an idea for me, dont hesitate.

                          Have a nice day !

                          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