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. How to avoid repeated execution of loading Qlibrary?
Forum Update on Monday, May 27th 2025

How to avoid repeated execution of loading Qlibrary?

Scheduled Pinned Locked Moved Unsolved General and Desktop
23 Posts 5 Posters 1.5k 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.
  • RogerBretonR RogerBreton

    In my humble application, I require the use of functions stored in a DLL which I manage to load in memory with the help of the Qlibrary object, like this :

      QLibrary myLib("DEVICE.dll");
    
        bool Result;
        Result = myLib.load();
    

    It works great. Then I use some typedef to resolve the DLL functions, like so :

    typedef DEVICE_ERROR_TYPES(__stdcall* Fn6)(void);
        Fn6 RB_StartMeasurement = reinterpret_cast<Fn6>(myLib.resolve("DEVICE_StartMeasurement"));
    

    Then I merely issue this code to make a measurement :

    sdkError = RB_StartMeasurement();
    

    It works wonder! Qlibrary allows me to access a DLL I could never access otherwise (believe me, I tried evertyhing).

    My problem? Looks like I can only take ONE measurement once the instrument is calibrated? See this dialog box :

    Normal.jpg

    See the Measure button? I should be able to press it repeatedly without the program crashing or hanging on me. But that's what happens, sadly?

    I suspect the problems stems from my "multiple loading of the DEVICE.dll"?

    You see, I don't know of a way I could load the library once and have it accessible to all functions? I tried moving the Qlibrary call every place I could inside my application but I am limited by the associated typedef definitions and declarations, as you can see, inside the Measure button, I have the call to Qlibrary followed by the typedefs :

    void MainWindow::on_btnMeasure_clicked()
    {
        QLibrary myLib("DEVICE.dll");
    
        bool Result;
        Result = myLib.load();
    
    typedef DEVICE_ERROR_TYPES(__stdcall* Fn6)(void);
        Fn6 RB_StartMeasurement = reinterpret_cast<Fn6>(myLib.resolve("DEVICE_StartMeasurement"));
    }
    

    I have the same Qlibrary / typedeg under each buttons in my interface. For example, under the Connect button, I have this code :

    void MainWindow::on_btnConnect_clicked(){
    
    
        QLibrary myLib("DEVICE.dll");
    
        bool Result;
        Result = myLib.load();
    
        typedef DEVICE_ERROR_TYPES(__stdcall* Fn1)(const DEVICE_PortInfo* inPortInfo, const uint32_km inTimeout);
        Fn1 RB_Connect = reinterpret_cast<Fn1>(myLib.resolve("DEVICE_Connect"));
    }
    

    At the beginning, I did not care that I was loading the same DLL over and over since it's less than 100K and I was too eager to see how far I could push this logic but I see the debugger take me into assembler code during subsequent Measure attempts? And I recognize some DLL function names show up on stake trace that have nothing to do with my resolved functions? To me, the problem stems from repeated loading of the DLL but I can't "prove" it (or get that out of the equation) until I find a way to load it once, globally, and have it shared by all the slots functions....

    I tried to run the code on another Windows machine but I immediately got "Segmentation faults" errors? And when I try to run my application on this machine, in Release mode, I immediately get this error :

    Test erro.jpg

    "Test" is the name of my application.

    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by jsulm
    #2

    @RogerBreton said in How to avoid repeated execution of loading Qlibrary?:

    I don't know of a way I could load the library once and have it accessible to all functions?

    Simply put the RB_StartMeasurement pointer as class member and initialize it to nullptr. Before using it later check whether it is nullptr, if it is load the lib and assign the pointer...
    Also make myLib class member.

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

    1 Reply Last reply
    1
    • RogerBretonR Offline
      RogerBretonR Offline
      RogerBreton
      wrote on last edited by
      #3

      @jsulm said in How to avoid repeated execution of loading Qlibrary?:

      Also make myLib class member.

      Here is the code of the MainWindow class :

      class MainWindow : public QMainWindow
      {
          Q_OBJECT   
          QLibrary myLib();
      
      typedef DEVICE_ERROR_TYPES(__stdcall* Fn6)(void);
          Fn6 RB_StartMeasurement = reinterpret_cast<Fn6>(myLib.resolve("DEVICE_StartMeasurement"));
      
      public:
          MainWindow(QWidget *parent = nullptr); 
          ~MainWindow();
      
      ...
      

      As you can see, I "made myLib a class member" and I tried to put the RB_StartMeasurement (pointer?) as a a "class member" as well but the compiler gives me a :

      reference to non-static member functions must be called; did you mean to call it with no arguments?

      That's where I'm lost....

      Roger Breton
      www.graxx.ca

      jsulmJ 1 Reply Last reply
      0
      • RogerBretonR RogerBreton

        @jsulm said in How to avoid repeated execution of loading Qlibrary?:

        Also make myLib class member.

        Here is the code of the MainWindow class :

        class MainWindow : public QMainWindow
        {
            Q_OBJECT   
            QLibrary myLib();
        
        typedef DEVICE_ERROR_TYPES(__stdcall* Fn6)(void);
            Fn6 RB_StartMeasurement = reinterpret_cast<Fn6>(myLib.resolve("DEVICE_StartMeasurement"));
        
        public:
            MainWindow(QWidget *parent = nullptr); 
            ~MainWindow();
        
        ...
        

        As you can see, I "made myLib a class member" and I tried to put the RB_StartMeasurement (pointer?) as a a "class member" as well but the compiler gives me a :

        reference to non-static member functions must be called; did you mean to call it with no arguments?

        That's where I'm lost....

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #4

        @RogerBreton said in How to avoid repeated execution of loading Qlibrary?:

        reinterpret_cast<Fn6>(myLib.resolve("DEVICE_StartMeasurement"));

        This should be done in the constructor

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

        1 Reply Last reply
        0
        • RogerBretonR Offline
          RogerBretonR Offline
          RogerBreton
          wrote on last edited by
          #5

          @jsulm said in How to avoid repeated execution of loading Qlibrary?:

          reinterpret_cast<Fn6>(myLib.resolve("DEVICE_StartMeasurement"));

          I moved "reinterpret_cast<Fn6>(myLib.resolve("DEVICE_StartMeasurement"));" in the constructor, so all I have in mainwindow.h is this :

          class MainWindow : public QMainWindow
          {
              Q_OBJECT   
              QLibrary myLib();
          
          typedef DEVICE_ERROR_TYPES(__stdcall* Fn6)(void);
          
          public:
              MainWindow(QWidget *parent = nullptr); 
              ~MainWindow();
          ...
          

          And in the "Constructor", I have this code :

          MainWindow::MainWindow(QWidget *parent)
              : QMainWindow(parent)       // Constructor
              , ui(new Ui::MainWindow)
          {
              ui->setupUi(this);
          
              QLibrary myLib("FDXSDK.dll");
              bool Result;
              Result = myLib.load();
              
              Fn6 RB_StartMeasurement = reinterpret_cast<Fn6>(myLib.resolve("FDX_StartMeasurement"));
              
          }
          
          

          Then, in the Measure button, I end up with this code :

          void MainWindow::on_btnMeasure_clicked()
          {
               sdkError = RB_StartMeasurement();
          

          For which I get :

          use of undeclared identifier 'RB_Startmeasurement'...

          Lost again... Maybe that reference to 'initialize with a null pointer' I'm missing?

          Roger Breton
          www.graxx.ca

          JonBJ 1 Reply Last reply
          0
          • RogerBretonR RogerBreton

            @jsulm said in How to avoid repeated execution of loading Qlibrary?:

            reinterpret_cast<Fn6>(myLib.resolve("DEVICE_StartMeasurement"));

            I moved "reinterpret_cast<Fn6>(myLib.resolve("DEVICE_StartMeasurement"));" in the constructor, so all I have in mainwindow.h is this :

            class MainWindow : public QMainWindow
            {
                Q_OBJECT   
                QLibrary myLib();
            
            typedef DEVICE_ERROR_TYPES(__stdcall* Fn6)(void);
            
            public:
                MainWindow(QWidget *parent = nullptr); 
                ~MainWindow();
            ...
            

            And in the "Constructor", I have this code :

            MainWindow::MainWindow(QWidget *parent)
                : QMainWindow(parent)       // Constructor
                , ui(new Ui::MainWindow)
            {
                ui->setupUi(this);
            
                QLibrary myLib("FDXSDK.dll");
                bool Result;
                Result = myLib.load();
                
                Fn6 RB_StartMeasurement = reinterpret_cast<Fn6>(myLib.resolve("FDX_StartMeasurement"));
                
            }
            
            

            Then, in the Measure button, I end up with this code :

            void MainWindow::on_btnMeasure_clicked()
            {
                 sdkError = RB_StartMeasurement();
            

            For which I get :

            use of undeclared identifier 'RB_Startmeasurement'...

            Lost again... Maybe that reference to 'initialize with a null pointer' I'm missing?

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #6

            @RogerBreton

             Fn6 RB_StartMeasurement = reinterpret_cast<Fn6>(myLib.resolve("FDX_StartMeasurement"));
            

            This declares RB_StartMeasurement as a local variable in method MainWindow::MainWindow(). That means you won't be able to access it another method, like MainWindow::on_btnMeasure_clicked(), as you're seeing from the undeclared identifier message.

            You want Fn6 RB_StartMeasurement to be a member variable of the MainWindow class, declared in the .h file. Then you assign it as you have done in MainWindow::MainWindow but without that type declaration in front of it, as:

            RB_StartMeasurement = reinterpret_cast<Fn6>(myLib.resolve("FDX_StartMeasurement"));
            // equivalent to
            this->RB_StartMeasurement = reinterpret_cast<Fn6>(myLib.resolve("FDX_StartMeasurement"));
            

            Now you can access RB_StartMeasurement()/this->RB_StartMeasurement() in other MainWindow methods, like you tried.

            1 Reply Last reply
            2
            • RogerBretonR Offline
              RogerBretonR Offline
              RogerBreton
              wrote on last edited by
              #7

              Thank you all for your patience and help...

              So, I made "Fn6 RB_StartMeasurement" a member variable of the MainWindow class, declared in the .h file, like this :

              class MainWindow : public QMainWindow
              {
                  Q_OBJECT    // Macro Meta Object Compiler
                  QLibrary myLib();
                  
                  typedef DEVICE_ERROR_TYPES(__stdcall* Fn6)(void);
                  Fn6 RB_StartMeasurement();
                  
              public:
                  MainWindow(QWidget *parent = nullptr); 
                  ~MainWindow();
              ...
              

              Then in MainWindow::MainWindow, I assign it, without the type declaration in front of it, like this :

              MainWindow::MainWindow(QWidget *parent)
                  : QMainWindow(parent)  
                  , ui(new Ui::MainWindow)
              {
                  ui->setupUi(this);
              
                  QLibrary myLib("DEVICE.dll");
              
                  bool Result;
                  Result = myLib.load();
                  
                  RB_StartMeasurement = reinterpret_cast<Fn6>(myLib.resolve("DEVICE_StartMeasurement"));
                  
              }
              
              

              But that gives me :

              reference to non-static member function must be called...

              I must still be missing something...

              Roger Breton
              www.graxx.ca

              JonBJ jsulmJ 2 Replies Last reply
              0
              • RogerBretonR RogerBreton

                Thank you all for your patience and help...

                So, I made "Fn6 RB_StartMeasurement" a member variable of the MainWindow class, declared in the .h file, like this :

                class MainWindow : public QMainWindow
                {
                    Q_OBJECT    // Macro Meta Object Compiler
                    QLibrary myLib();
                    
                    typedef DEVICE_ERROR_TYPES(__stdcall* Fn6)(void);
                    Fn6 RB_StartMeasurement();
                    
                public:
                    MainWindow(QWidget *parent = nullptr); 
                    ~MainWindow();
                ...
                

                Then in MainWindow::MainWindow, I assign it, without the type declaration in front of it, like this :

                MainWindow::MainWindow(QWidget *parent)
                    : QMainWindow(parent)  
                    , ui(new Ui::MainWindow)
                {
                    ui->setupUi(this);
                
                    QLibrary myLib("DEVICE.dll");
                
                    bool Result;
                    Result = myLib.load();
                    
                    RB_StartMeasurement = reinterpret_cast<Fn6>(myLib.resolve("DEVICE_StartMeasurement"));
                    
                }
                
                

                But that gives me :

                reference to non-static member function must be called...

                I must still be missing something...

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #8

                @RogerBreton said in How to avoid repeated execution of loading Qlibrary?:

                Fn6 RB_StartMeasurement();

                You want a function pointer variable, as you had originally, i.e.

                 Fn6 RB_StartMeasurement;
                

                not a function call, with the round parentheses after it.

                1 Reply Last reply
                2
                • RogerBretonR RogerBreton

                  Thank you all for your patience and help...

                  So, I made "Fn6 RB_StartMeasurement" a member variable of the MainWindow class, declared in the .h file, like this :

                  class MainWindow : public QMainWindow
                  {
                      Q_OBJECT    // Macro Meta Object Compiler
                      QLibrary myLib();
                      
                      typedef DEVICE_ERROR_TYPES(__stdcall* Fn6)(void);
                      Fn6 RB_StartMeasurement();
                      
                  public:
                      MainWindow(QWidget *parent = nullptr); 
                      ~MainWindow();
                  ...
                  

                  Then in MainWindow::MainWindow, I assign it, without the type declaration in front of it, like this :

                  MainWindow::MainWindow(QWidget *parent)
                      : QMainWindow(parent)  
                      , ui(new Ui::MainWindow)
                  {
                      ui->setupUi(this);
                  
                      QLibrary myLib("DEVICE.dll");
                  
                      bool Result;
                      Result = myLib.load();
                      
                      RB_StartMeasurement = reinterpret_cast<Fn6>(myLib.resolve("DEVICE_StartMeasurement"));
                      
                  }
                  
                  

                  But that gives me :

                  reference to non-static member function must be called...

                  I must still be missing something...

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #9

                  @RogerBreton said in How to avoid repeated execution of loading Qlibrary?:

                  QLibrary myLib("DEVICE.dll");

                  Why do you declare another myLib inside constructor?! Use the class instance myLib.

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

                  1 Reply Last reply
                  1
                  • RogerBretonR Offline
                    RogerBretonR Offline
                    RogerBreton
                    wrote on last edited by
                    #10

                    I fixed the header this way :

                    class MainWindow : public QMainWindow
                    {
                        Q_OBJECT    // Macro Meta Object Compiler
                        QLibrary myLib();
                        
                        typedef DEVICE_ERROR_TYPES(__stdcall* Fn6)(void);
                        Fn6 RB_StartMeasurement;
                    ...
                    

                    But then, in the Constructor, I have this code :

                    MainWindow::MainWindow(QWidget *parent)
                        : QMainWindow(parent)       // Constructor
                        , ui(new Ui::MainWindow)
                    {
                        ui->setupUi(this);
                    
                        bool Result;
                        Result = myLib.load("DEVICE.dll");
                        
                        RB_StartMeasurement = reinterpret_cast<Fn6>(myLib.resolve("FDX_StartMeasurement"));
                        
                    }
                    ...
                    

                    Notice how, this time, I use the myLib class instance? But I must not have the correct logic because the compiler says :

                    reference to non-static member function must be called

                    Same error for the RB_StartMeasurement :(

                    Boy! Thank you guys for your patience!

                    Roger Breton
                    www.graxx.ca

                    JonBJ 1 Reply Last reply
                    0
                    • RogerBretonR RogerBreton

                      I fixed the header this way :

                      class MainWindow : public QMainWindow
                      {
                          Q_OBJECT    // Macro Meta Object Compiler
                          QLibrary myLib();
                          
                          typedef DEVICE_ERROR_TYPES(__stdcall* Fn6)(void);
                          Fn6 RB_StartMeasurement;
                      ...
                      

                      But then, in the Constructor, I have this code :

                      MainWindow::MainWindow(QWidget *parent)
                          : QMainWindow(parent)       // Constructor
                          , ui(new Ui::MainWindow)
                      {
                          ui->setupUi(this);
                      
                          bool Result;
                          Result = myLib.load("DEVICE.dll");
                          
                          RB_StartMeasurement = reinterpret_cast<Fn6>(myLib.resolve("FDX_StartMeasurement"));
                          
                      }
                      ...
                      

                      Notice how, this time, I use the myLib class instance? But I must not have the correct logic because the compiler says :

                      reference to non-static member function must be called

                      Same error for the RB_StartMeasurement :(

                      Boy! Thank you guys for your patience!

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by
                      #11

                      @RogerBreton said in How to avoid repeated execution of loading Qlibrary?:

                      Notice how, this time, I use the myLib class instance? But I must not have the correct logic because the compiler says :

                      reference to non-static member function must be called

                      You have QLibrary myLib();. You like those () parentheses, don't you? ;-) You are going to call myLib.load("DEVICE.dll"). Don't you think your declaration should be QLibrary myLib; instead?

                      1 Reply Last reply
                      1
                      • RogerBretonR Offline
                        RogerBretonR Offline
                        RogerBreton
                        wrote on last edited by
                        #12

                        I notice, afterwards, that the declaration should not have parentheses :

                        class MainWindow : public QMainWindow
                        {
                            Q_OBJECT
                            QLibrary myLib;
                            
                            typedef FDXSDK_ERROR_TYPES(__stdcall* Fn6)(void);
                            Fn6 RB_StartMeasurement;
                        ...
                        

                        But then, in the constuctor, I could not understand why I was still the error "Too many arguments to function call" when I tried to pass the name of the DLL to the load library function:

                        MainWindow::MainWindow(QWidget *parent)
                            : QMainWindow(parent)       // Constructor
                            , ui(new Ui::MainWindow)
                        {
                            ui->setupUi(this);
                        
                            bool Result;
                            Result = myLib.load("DEVICE.dll");
                              
                            RB_StartMeasurement = reinterpret_cast<Fn6>(myLib.resolve("FDX_StartMeasurement"));
                            
                        }
                        

                        It's one thing to declare myLib as of type Qlibrary in the header but I don't understand, why in the implementation, the compiler would complain?
                        jsum commented earlier :

                        Why do you declare another myLib inside constructor?! Use the class instance myLib.

                        So I think, that is what I'm doing, using the class instance myLib.
                        Unless I leave the call to Load without arguments, like this :

                           bool Result;
                            Result = myLib.load();
                        

                        But this does not seem to make sense?

                        The documentation states:

                        The resolve() function implicitly tries to load the library if it has not been loaded yet.
                        But where will it gets the name of the DLL to load in memory, if it is never specified in the first place?

                        Take the Measure button code :

                        void MainWindow::on_btnMeasure_clicked()
                        {
                             sdkError = RB_StartMeasurement();
                        

                        Where is the application going to get the DLL from?

                        Roger Breton
                        www.graxx.ca

                        Christian EhrlicherC 1 Reply Last reply
                        0
                        • RogerBretonR RogerBreton

                          I notice, afterwards, that the declaration should not have parentheses :

                          class MainWindow : public QMainWindow
                          {
                              Q_OBJECT
                              QLibrary myLib;
                              
                              typedef FDXSDK_ERROR_TYPES(__stdcall* Fn6)(void);
                              Fn6 RB_StartMeasurement;
                          ...
                          

                          But then, in the constuctor, I could not understand why I was still the error "Too many arguments to function call" when I tried to pass the name of the DLL to the load library function:

                          MainWindow::MainWindow(QWidget *parent)
                              : QMainWindow(parent)       // Constructor
                              , ui(new Ui::MainWindow)
                          {
                              ui->setupUi(this);
                          
                              bool Result;
                              Result = myLib.load("DEVICE.dll");
                                
                              RB_StartMeasurement = reinterpret_cast<Fn6>(myLib.resolve("FDX_StartMeasurement"));
                              
                          }
                          

                          It's one thing to declare myLib as of type Qlibrary in the header but I don't understand, why in the implementation, the compiler would complain?
                          jsum commented earlier :

                          Why do you declare another myLib inside constructor?! Use the class instance myLib.

                          So I think, that is what I'm doing, using the class instance myLib.
                          Unless I leave the call to Load without arguments, like this :

                             bool Result;
                              Result = myLib.load();
                          

                          But this does not seem to make sense?

                          The documentation states:

                          The resolve() function implicitly tries to load the library if it has not been loaded yet.
                          But where will it gets the name of the DLL to load in memory, if it is never specified in the first place?

                          Take the Measure button code :

                          void MainWindow::on_btnMeasure_clicked()
                          {
                               sdkError = RB_StartMeasurement();
                          

                          Where is the application going to get the DLL from?

                          Christian EhrlicherC Offline
                          Christian EhrlicherC Offline
                          Christian Ehrlicher
                          Lifetime Qt Champion
                          wrote on last edited by
                          #13

                          @RogerBreton said in How to avoid repeated execution of loading Qlibrary?:

                          But where will it gets the name of the DLL to load in memory, if it is never specified in the first place?

                          Via the ctor

                          I was still the error "Too many arguments to function call" when I tried to pass the name of the DLL to the load library function:

                          Because you declared a class function named myLib() which returns a QLibrary object.

                          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                          Visit the Qt Academy at https://academy.qt.io/catalog

                          1 Reply Last reply
                          1
                          • RogerBretonR Offline
                            RogerBretonR Offline
                            RogerBreton
                            wrote on last edited by
                            #14

                            I wanted to try the changes in debug mode but I immediately ran into the following error message :

                            Error.jpg

                            Time for a cup of coffee...

                            Roger Breton
                            www.graxx.ca

                            JonBJ 1 Reply Last reply
                            0
                            • Christian EhrlicherC Offline
                              Christian EhrlicherC Offline
                              Christian Ehrlicher
                              Lifetime Qt Champion
                              wrote on last edited by
                              #15

                              @RogerBreton said in How to avoid repeated execution of loading Qlibrary?:

                              Time for a cup of coffee...

                              I would rather say - time for a debugging session :)

                              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                              Visit the Qt Academy at https://academy.qt.io/catalog

                              1 Reply Last reply
                              1
                              • RogerBretonR RogerBreton

                                I wanted to try the changes in debug mode but I immediately ran into the following error message :

                                Error.jpg

                                Time for a cup of coffee...

                                JonBJ Offline
                                JonBJ Offline
                                JonB
                                wrote on last edited by JonB
                                #16

                                @RogerBreton
                                If, from what you have shown, you presently have:

                                   bool Result;
                                    Result = myLib.load();
                                RB_StartMeasurement = reinterpret_cast<Fn6>(myLib.resolve("FDX_StartMeasurement"));
                                sdkError = RB_StartMeasurement();
                                

                                without checking the intermediate return result variables, RB_StartMeasurement may be nullptr. Then RB_StartMeasurement() would cause a SIGSEGV?

                                RogerBretonR 1 Reply Last reply
                                1
                                • JonBJ JonB

                                  @RogerBreton
                                  If, from what you have shown, you presently have:

                                     bool Result;
                                      Result = myLib.load();
                                  RB_StartMeasurement = reinterpret_cast<Fn6>(myLib.resolve("FDX_StartMeasurement"));
                                  sdkError = RB_StartMeasurement();
                                  

                                  without checking the intermediate return result variables, RB_StartMeasurement may be nullptr. Then RB_StartMeasurement() would cause a SIGSEGV?

                                  RogerBretonR Offline
                                  RogerBretonR Offline
                                  RogerBreton
                                  wrote on last edited by
                                  #17

                                  @JonB I don't dare say RB_StartMeasurement may be a nullptr in ALL LIKELIHOOD, and that maybe the cause of the segmentation fault. That is exactly my hypothesis. So, if that is the case, this proves my intuition : where is the application getting the DLL from? If its name isn't specified anywhere? It is not in the PRO file.

                                  I was thinking, perhaps, I should test whether the library is loaded before calling RB_StartMeasurement? And if it is not loaded, then load it? But that would not explain why I get the SIGSEV when the application tries to load? Or is it happening in the constructor?

                                  Somehow, I must be missing some important piece of the puzzle -- I'll continue to look around but I am optimistic...

                                  Roger Breton
                                  www.graxx.ca

                                  JonBJ 1 Reply Last reply
                                  0
                                  • RogerBretonR RogerBreton

                                    @JonB I don't dare say RB_StartMeasurement may be a nullptr in ALL LIKELIHOOD, and that maybe the cause of the segmentation fault. That is exactly my hypothesis. So, if that is the case, this proves my intuition : where is the application getting the DLL from? If its name isn't specified anywhere? It is not in the PRO file.

                                    I was thinking, perhaps, I should test whether the library is loaded before calling RB_StartMeasurement? And if it is not loaded, then load it? But that would not explain why I get the SIGSEV when the application tries to load? Or is it happening in the constructor?

                                    Somehow, I must be missing some important piece of the puzzle -- I'll continue to look around but I am optimistic...

                                    JonBJ Offline
                                    JonBJ Offline
                                    JonB
                                    wrote on last edited by
                                    #18

                                    @RogerBreton

                                    bool Result;
                                    Result = myLib.load();
                                    if (!Result)
                                        qDebug() << "This is bad...";
                                    RB_StartMeasurement = reinterpret_cast<Fn6>(myLib.resolve("FDX_StartMeasurement"));
                                    if (RB_StartMeasurement  == nullptr)
                                        qDebug() << "This is bad.  Get ready for SEGV if you call RB_StartMeasurement() now...";
                                    sdkError = RB_StartMeasurement();
                                    
                                    1 Reply Last reply
                                    0
                                    • RogerBretonR Offline
                                      RogerBretonR Offline
                                      RogerBreton
                                      wrote on last edited by
                                      #19

                                      I declared the RB_StartMeasurement as NULL in mainwindow.h :

                                      class MainWindow : public QMainWindow
                                      {
                                          Q_OBJECT
                                          QLibrary myLib;
                                      
                                          typedef DEVICE_ERROR_TYPES(__stdcall* Fn6)(void);
                                          Fn6 RB_StartMeasurement = NULL;
                                      
                                      

                                      But I still get the Segmentation Fault...

                                      Roger Breton
                                      www.graxx.ca

                                      1 Reply Last reply
                                      0
                                      • SGaistS Offline
                                        SGaistS Offline
                                        SGaist
                                        Lifetime Qt Champion
                                        wrote on last edited by
                                        #20

                                        Hi,

                                        Did you implement @JonB´s suggestion ?

                                        Start in debug and you should see exactly where it fails.

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

                                        RogerBretonR 1 Reply Last reply
                                        0
                                        • SGaistS SGaist

                                          Hi,

                                          Did you implement @JonB´s suggestion ?

                                          Start in debug and you should see exactly where it fails.

                                          RogerBretonR Offline
                                          RogerBretonR Offline
                                          RogerBreton
                                          wrote on last edited by
                                          #21

                                          @SGaist That is exactly what I do :

                                          I found the culprit...

                                          DEVICE_ERROR_TYPES sdkError = RB_RegisterDeviceEventHandler(EventNotice);
                                          
                                          

                                          The above function is a static member function declared in SomeClassName... which was working fine before ... The EventNotice function is also part of the same class.

                                          Roger Breton
                                          www.graxx.ca

                                          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