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. function is blocked ! The function is created as dll exported function use QTimer QEventLoop, when is preferenced in visual studio.
Qt 6.11 is out! See what's new in the release blog

function is blocked ! The function is created as dll exported function use QTimer QEventLoop, when is preferenced in visual studio.

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 1.3k Views
  • 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.
  • C Offline
    C Offline
    changtj
    wrote on last edited by changtj
    #1

    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.

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      What is the problem?

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      C 1 Reply Last reply
      0
      • VRoninV VRonin

        What is the problem?

        C Offline
        C Offline
        changtj
        wrote on last edited by
        #3

        @VRonin
        the function block.

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          yes, el.exec(); is a blocking call so the function is doing exactly what you are telling it to do

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          C 1 Reply Last reply
          2
          • VRoninV VRonin

            yes, el.exec(); is a blocking call so the function is doing exactly what you are telling it to do

            C Offline
            C Offline
            changtj
            wrote on last edited by changtj
            #5

            @VRonin

            //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).

            1 Reply Last reply
            0
            • VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by
              #6

              I think QEventLoop needs a QCoreApplication to be created before being usable

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              1 Reply Last reply
              3

              • Login

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