Home > Mobile >  C # call DLL written in qt, signals and slots function cannot be used
C # call DLL written in qt, signals and slots function cannot be used

Time:10-17

Using Qt generate dynamic link library DLL files, without interface,
Use custom in the process of a class, class contains connet, specific code is as follows:
The definition of a class:
The class testTimer: public QObject
{
Q_OBJECT
Public:
Explicit testTimer (parent QObject *=nullptr);
QTimer * testtimer=new QTimer ();
Int value1=0;
QMetaObject: : Connection flag;
Private slots:
Void calTest ();
};

Class declaration:
TestTimer: : testTimer (QObject * parent) : QObject (parent)
{
Flag=connect (testtimer, & amp; QTimer: : timeout, [=] ()
{
Value1=value1 + 1;
}
);

Testtimer - & gt; Start (1000);
}

Void testTimer: : calTest ()
{
Value1=value1 + 1;
}

The use of class two usage
Method one: directly in the main
TestTimer * test11=new testTimer ();//using the class defines a function

Extern "C" __declspec (dllexport) int start ();//DLL
Int the start ()
{
Return test11 - & gt; Value1.//returns the value of value1
}

Method 2: borrow someone else to write the display interface in c # class

Call in the interface class

Currenttest testTimer *=new testTimer ();//define


Void MainWindow: : on_pushButton_2_clicked ()
{
The UI - & gt; DoubleSpinBox - & gt; SetValue (currenttest - & gt; Value1);
}//a button in the interface, click the button pop-up numerical

In c #, click a button to 1, and bring up a Qt interface, written
Click on the button 2, function value1 value of an interface

The result is that the button 1 click on_pushButton_2 interface, value1 value is changing all the time at this time, in line with expectations
Click on the button 2 value1 value is always 0,

Does anyone know what reason? I don't have to add something less?

CodePudding user response:

CodePudding user response:

Picture is the final result, it can be seen directly to invoke a custom class that reads value1 value, values of value1,
But I'm in the interface to invoke a custom class, then read value1 values, value1 values are changing,
  •  Tags:  
  • Qt
  • Related