I
I
Ilnur2018-03-13 12:39:08
Qt
Ilnur, 2018-03-13 12:39:08

How to connect one external library using QLibrary and work with two fixtures independently?

Hello everyone)
I created a library that has the following function:

float getFloat(){
    result_float = (float)i++; //для теста, потом здесь будут данные, которые считываются с прибора
    return result_float;  
}

Created a class for working with libraries:
class ConnectComDevice
{
private: 
    float result;

public:
    void getFloat()
    {
        QLibrary lib ( LIB_NAME );
        if( !lib.load() ) {
            qDebug() << "Loading failed!";
        }
        
        typedef float ( *outputFloat )();
        outputFloat outputFloatd;
        for (int i=0; i<5; i++)
        {
            outputFloatd = ( outputFloat ) lib.resolve( "getFloat" );
            if( outputFloatd ) {
                qDebug() << outputFloatd();
            }
        }
    }

};

I declare two class objects:
ConnectComDevice connectDevice();
connectDevice.getFloat();

ConnectComDevice connectDevice1();
connectDevice1.getFloat();

It seems to be how you should get:
spoiler
0
1
2
3
4
5
0
1
2
3
4

but I get:
spoiler

0
1
2
3
4
5
6
7
8
9

i.e. it works as one class, but I need them to work independently.
How can this be implemented?
ps:
spoiler
работают независимо, если создать копию dll (first.dll second.dll) и подключиться два раза. Но это решение мне не нравится

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
Jacob E, 2018-03-13
@Il_noor

Declare a class inside the library, include the library, create two objects of your class in the program, and use them.
Now you are trying to include the library twice, it does not make sense. Well, then, QLibrary is also optional, just write the library file and header in the pro file: doc.qt.io/qtcreator/creator-project-qmake-librarie...

P
polar_winter, 2018-03-17
@polar_winter

Your class method pulls a function that uses a global variable. In order for the value of a variable to correspond to an instance of a class, it must be a member of it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question