Home > Back-end >  [QT, c #] called QT DLL written in c # code of signals and slots
[QT, c #] called QT DLL written in c # code of signals and slots

Time:10-15

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:

Above is the result in figure 4, the same class, using qt interface, value1 values are in change, two value1 values to be obtained directly without change,
I manually triggered, add a button, click on the, let value1 value add 1, direct call value1 values also change + 1!