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. As dynamic libraries to use class variables?
Forum Updated to NodeBB v4.3 + New Features

As dynamic libraries to use class variables?

Scheduled Pinned Locked Moved Solved General and Desktop
50 Posts 4 Posters 13.0k Views 3 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.
  • M Offline
    M Offline
    Mikee
    wrote on last edited by Mikee
    #23

    When i do this same error appers:
    C:\Qt\project\MyCandleSrick\mainwindow.h:4: error: QMainWindow: No such file or directory

    In the file C:/Qt/project/MyCandleSrick/mainwindow.h:
    4:#include <QMainWindow>

    mrjjM 1 Reply Last reply
    0
    • M Mikee

      When i do this same error appers:
      C:\Qt\project\MyCandleSrick\mainwindow.h:4: error: QMainWindow: No such file or directory

      In the file C:/Qt/project/MyCandleSrick/mainwindow.h:
      4:#include <QMainWindow>

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #24

      @Mikee
      Well you library is with

      QT -= gui

      so it dont know QMainwindow type ( or any Qt widget type)

      1 Reply Last reply
      1
      • M Offline
        M Offline
        Mikee
        wrote on last edited by
        #25

        I fixed strategycod.pro:

        QT       += core gui
        
        TARGET = StrategyCod
        TEMPLATE = lib
        
        DEFINES += STRATEGYCOD_LIBRARY
        DEFINES += QT_DEPRECATED_WARNINGS
        SOURCES += \
                strategycod.cpp
        
        HEADERS += \
                strategycod.h \
                strategycod_global.h 
        
        unix {
            target.path = /usr/lib
            INSTALLS += target
        }
        INCLUDEPATH = "C:/Qt/project/MyCandleSrick"
        

        But the error is the same.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Mikee
          wrote on last edited by
          #26

          I done this in strategycod.pro

          INCLUDEPATH = "C:/Qt/project/MyCandleSrick"  "C:/Qt/Qt5.9.2/5.9.2/Src/qtbase/include/QtWidgets"
          

          Now it included <QMainWindow>. But it isnt working now

          extern "C" {STRATEGYCODSHARED_EXPORT void StrategyCod(MainWinow * main);}
          

          and

          void StrategyCod(MainWinow * main)
          

          errors:
          C:\Qt\project\StrategyCod\strategycod.h:7: error: variable or field 'StrategyCod' declared void
          extern "C" {STRATEGYCODSHARED_EXPORT void StrategyCod(MainWinow * main);}
          ^
          C:\Qt\project\StrategyCod\strategycod.h:7: error: 'MainWinow' was not declared in this scope
          C:\Qt\project\StrategyCod\strategycod.h:7: error: 'main' was not declared in this scope
          extern "C" {STRATEGYCODSHARED_EXPORT void StrategyCod(MainWinow * main);}
          ^
          C:\Qt\project\StrategyCod\strategycod.cpp:9: оerror: variable or field 'StrategyCod' declared void
          void StrategyCod(MainWinow * main)
          ^
          C:\Qt\project\StrategyCod\strategycod.cpp:9: error: 'MainWinow' was not declared in this scope
          C:\Qt\project\StrategyCod\strategycod.cpp:9: error: 'main' was not declared in this scope
          void StrategyCod(MainWinow * main)

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

            Because when you do INCLUDEPATH = you replace the content of that variable with what follows. Use INCLUDEPATH += to append your folders to it.

            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
            2
            • M Offline
              M Offline
              Mikee
              wrote on last edited by
              #28

              Now all includes are working.
              When I use function

              void StrategyCod(MainWindow * main)
              {
                  //MainWindow w;
                  main->NBar;
                  qDebug()<<"Library work2"<<main->NBar;//<<w.NBar;
              }
              

              qDebug message is not a valid value NBar

              1 Reply Last reply
              0
              • M Offline
                M Offline
                Mikee
                wrote on last edited by
                #29

                I think that need to do reference class variable. But this code isn't working

                void StrategyCod(/*MainWindow * main*/)
                {
                    long long &NBar1 =MainWindow.NBar;
                    qDebug()<<"Library work2";//<<w.NBar;
                }
                
                

                How can i do reference?

                mrjjM 1 Reply Last reply
                0
                • M Mikee

                  I think that need to do reference class variable. But this code isn't working

                  void StrategyCod(/*MainWindow * main*/)
                  {
                      long long &NBar1 =MainWindow.NBar;
                      qDebug()<<"Library work2";//<<w.NBar;
                  }
                  
                  

                  How can i do reference?

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by mrjj
                  #30

                  @Mikee

                  via the parameter ( main or what u called it)

                  void StrategyCod(MainWindow * main) {
                      qDebug()<<"Library work2"<<main->NBar;
                  }
                  

                  if NBAr is wrong, then something else is wrong. not the function
                  it might be you call StrategyCod BEFORE setting it in mainwindow or
                  something like that.

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    Mikee
                    wrote on last edited by
                    #31

                    I checked:
                    library:
                    void StrategyCod(double Parametr)

                    {
                        MainWindow *w;
                        qDebug()<<"Library work2"<<Parametr<<w->NBar;
                    }
                    

                    main.cpp:

                    QLibrary MyLib("C:\\Qt\\project\\build-StrategyCod-Desktop_Qt_5_9_2_MinGW_32bit-Debug\\debug\\StrategyCod");  
                        MyLib.load();
                        typedef void (*MyPrototype)();
                        MyPrototype StrategyCod = (MyPrototype) MyLib.resolve("StrategyCod");
                        qDebug()<<w.NBar;  //NBar=0 is hear 
                        StrategyCod();  //NBar=5943858560 is hear 
                        MyLib.unload();
                    

                    Maybe here typedef void (*MyPrototype)(); need append void (*MyPrototype)(class); ?

                    mrjjM 1 Reply Last reply
                    0
                    • M Mikee

                      I checked:
                      library:
                      void StrategyCod(double Parametr)

                      {
                          MainWindow *w;
                          qDebug()<<"Library work2"<<Parametr<<w->NBar;
                      }
                      

                      main.cpp:

                      QLibrary MyLib("C:\\Qt\\project\\build-StrategyCod-Desktop_Qt_5_9_2_MinGW_32bit-Debug\\debug\\StrategyCod");  
                          MyLib.load();
                          typedef void (*MyPrototype)();
                          MyPrototype StrategyCod = (MyPrototype) MyLib.resolve("StrategyCod");
                          qDebug()<<w.NBar;  //NBar=0 is hear 
                          StrategyCod();  //NBar=5943858560 is hear 
                          MyLib.unload();
                      

                      Maybe here typedef void (*MyPrototype)(); need append void (*MyPrototype)(class); ?

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #32

                      @Mikee
                      Yes it must all match.

                      typedef void (*MyPrototype)();

                      means pointer to function takes no parameters
                      which is untrue.

                      1 Reply Last reply
                      0
                      • M Offline
                        M Offline
                        Mikee
                        wrote on last edited by
                        #33

                        But what to do with NBar?

                        void StrategyCod()
                        {
                            MainWindow *w;
                            qDebug()<<"Library work2"<<w->NBar;
                          
                        }
                        
                        jsulmJ 1 Reply Last reply
                        0
                        • M Mikee

                          But what to do with NBar?

                          void StrategyCod()
                          {
                              MainWindow *w;
                              qDebug()<<"Library work2"<<w->NBar;
                            
                          }
                          
                          jsulmJ Offline
                          jsulmJ Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on last edited by
                          #34

                          @Mikee

                          typedef void (*MyPrototype)(MainWindow *w);
                          

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

                          1 Reply Last reply
                          0
                          • M Offline
                            M Offline
                            Mikee
                            wrote on last edited by Mikee
                            #35

                            I have done this and it's working

                             QLibrary MyLib("C:\\Qt\\project\\build-StrategyCod-Desktop_Qt_5_9_2_MinGW_32bit-Debug\\debug\\StrategyCod");  
                                MyLib.load();
                                typedef void (*MyPrototype)(MainWindow *);
                                MyPrototype StrategyCod = (MyPrototype) MyLib.resolve("StrategyCod");
                                StrategyCod(&w);  
                                qDebug()<<"q1"<< q1;
                                MyLib.unload();
                            

                            Thank you

                            1 Reply Last reply
                            1
                            • mrjjM Offline
                              mrjjM Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on last edited by
                              #36

                              Congrats :)

                              1 Reply Last reply
                              1
                              • M Offline
                                M Offline
                                Mikee
                                wrote on last edited by
                                #37

                                I have are new problem.

                                qDebug()<<NBar;
                                

                                return NBar=1064,

                                qDebug()<<"Library work2"<< Parametr<<w->NBar;
                                

                                return NBar=0
                                In class MainWindow:

                                void MainWindow::on_ButtonRuneOne_clicked()//запуск стратегии на одном ядре
                                {
                                    bool ok;
                                    double d = QInputDialog::getDouble(this, tr("ParametrForStrategy"),
                                                                           tr("double:"), 37.56, -100000, 100000, 6, &ok);
                                    if (ok) {ParametrForStrategyCod=d; }
                                
                                    QLibrary MyLib("C:\\Qt\\project\\build-StrategyCod-Desktop_Qt_5_9_2_MinGW_32bit-Debug\\debug\\StrategyCod");  
                                    MyLib.load();
                                    typedef void (*MyPrototype)(double,MainWindow *);
                                    MyPrototype StrategyCod = (MyPrototype) MyLib.resolve("StrategyCod");
                                    MainWindow w;
                                    qDebug()<<NBar;
                                    StrategyCod(ParametrForStrategyCod,&w);  /
                                    MyLib.unload();
                                }
                                

                                In library:

                                void StrategyCod(double Parametr, MainWindow *w)
                                {
                                    qDebug()<<"Library work2"<< Parametr<<w->NBar;
                                }
                                

                                But in main.cpp it works good. How can I fix problem with link of object class?

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

                                  You're passing w to your method which is not the current MainWindow object you are calling StrategyCod from.

                                  Pass this to the method.

                                  On a side note, you are doing some pretty convoluted stuff here for what seems to be a pretty simple task. I'd encourage you to re-think a bit the design of your application.

                                  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
                                  3
                                  • M Offline
                                    M Offline
                                    Mikee
                                    wrote on last edited by
                                    #39

                                    Thank you. I wrote it like this

                                    StrategyCod(ParametrForStrategyCod,this); 
                                    

                                    and it works

                                    1 Reply Last reply
                                    0
                                    • M Offline
                                      M Offline
                                      Mikee
                                      wrote on last edited by
                                      #40

                                      How can I create lamda function in the slot of the class?

                                      
                                             QVector <double> Perebor1;
                                             for (double i=d1;i<=d2;i=i+d3) 
                                             {
                                                 Perebor1.append(i);
                                             }
                                             QLibrary MyLib("C:\\Qt\\project\\build-StrategyCod-Desktop_Qt_5_9_2_MinGW_32bit-Debug\\debug\\StrategyCod");  
                                             MyLib.load();
                                             typedef void (*MyPrototype)(double,MainWindow *);
                                             MyPrototype StrategyCod = (MyPrototype) MyLib.resolve("StrategyCod");
                                             //StrategyCod(ParametrForStrategyCod,this);  
                                             QFuture<void> Perebor2 = QtConcurrent::map(Perebor1,[&](const double& d){ StrategyCod(d,this);}); 
                                             MyLib.unload();
                                      
                                      1 Reply Last reply
                                      0
                                      • M Offline
                                        M Offline
                                        Mikee
                                        wrote on last edited by Mikee
                                        #41

                                        And if I do, the function does not work.

                                        void StrategyCod(double Parametr, MainWindow *w)
                                        {
                                            qDebug()<<"Library work2"<< Parametr<<w->NBar;
                                            w->NBar=2000;
                                        }
                                        

                                        error:
                                        Invalid parameter passed to C runtime function.
                                        Invalid parameter passed to C runtime function.

                                        1 Reply Last reply
                                        0
                                        • mrjjM Offline
                                          mrjjM Offline
                                          mrjj
                                          Lifetime Qt Champion
                                          wrote on last edited by
                                          #42

                                          Well if Perebor2 still runs when you do MyLib.unload()
                                          its not so nice for it...

                                          1 Reply Last reply
                                          1

                                          • Login

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