Unsolved function is blocked ! The function is created as dll exported function use QTimer QEventLoop, when is preferenced in visual studio.
-
code as follow
//qt #ifdef QTFTP_DLL_EXPORT #define DLL_API extern "C" __declspec( dllexport) #else #define DLL_API extern "C" __declspec( dllimport) #endif #include <QTimer> #include <QEventLoop> DLL_API void __stdcall MyFtpTestTimer2() { QTimer qt; QEventLoop el; QObject::connect( &qt, SIGNAL(timeout()), &el, SLOT(quit())); qt.start( 1000); el.exec(); }
//visual studio 2017 sdk8.1 void CMyDlg::OnTest() { // TODO: 在此添加命令处理程序代码 MyFtpTestTimer2(); }
and the cpu is taked up more.
-
What is the problem?
-
@VRonin
the function block. -
yes,
el.exec();
is a blocking call so the function is doing exactly what you are telling it to do -
//your code here QTimer qt; DLL_API void __stdcall MyFtpTestTimer2() { QTimer qt; QEventLoop el; QObject::connect( &qt, SIGNAL(timeout()), &el, SLOT(quit())); qt.start( 1000); el.exec(); }
the function do not return any more in vs. when it is used in qt it only block 1000 ms when qt timed out. as qt.start( 1000).
-
I think
QEventLoop
needs aQCoreApplication
to be created before being usable