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. Using Qt in a .dll

Using Qt in a .dll

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 782 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.
  • P Offline
    P Offline
    psyfl
    wrote on last edited by
    #1

    Hi. I'm attempting to make a DLL with an entry point that is executed when LoadLibrary is called. In the entry point, the DLL creates a thread, and then I need the thread to connect to my nodejs server with a websocket endpoint. I would like to do this with QTcpSocket. I have tried to do this, but whenever I use any Qt features (such as simply declaring a QTcpSocket), the entry point of my DLL fails to execute when LoadLibrary is called. Is it possible to do this and if so, how can I go about doing it?

    JonBJ 1 Reply Last reply
    0
    • P psyfl

      Hi. I'm attempting to make a DLL with an entry point that is executed when LoadLibrary is called. In the entry point, the DLL creates a thread, and then I need the thread to connect to my nodejs server with a websocket endpoint. I would like to do this with QTcpSocket. I have tried to do this, but whenever I use any Qt features (such as simply declaring a QTcpSocket), the entry point of my DLL fails to execute when LoadLibrary is called. Is it possible to do this and if so, how can I go about doing it?

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by JonB
      #2

      @psyfl
      I believe you have to create something like a QCoreApplication before you can make any Qt calls, have you done anything like that? Have a read of https://stackoverflow.com/questions/2150488/using-a-qt-based-dll-in-a-non-qt-application, or https://stackoverflow.com/questions/17222584/how-to-create-a-qt-shared-library-for-a-non-qt-application ?

      but whenever I use any Qt features (such as simply declaring a QTcpSocket),
      the entry point of my DLL fails to execute when LoadLibrary is called

      If it fails this early, another possibility might be failing to find any further dependent libraries to load, though I wonder if you'd get a specific error message for that if it happens.

      1 Reply Last reply
      1
      • M Offline
        M Offline
        MrShawn
        wrote on last edited by
        #3

        @JonB is right. I made some DLLs to be called by non Qt code. The problem is any code that uses the Qt event loop will always need an event loop. This means at the very least your DLL needs to startup a QCoreApplication.

        JonBJ 1 Reply Last reply
        1
        • M MrShawn

          @JonB is right. I made some DLLs to be called by non Qt code. The problem is any code that uses the Qt event loop will always need an event loop. This means at the very least your DLL needs to startup a QCoreApplication.

          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by
          #4

          @MrShawn
          I think it's even deeper than that. I believe you need to have created a QCoreApplication before you can create anything derived from QObject (regardless of Qt event loop or not). And since OP's QTcpSocket is derived from QObject I don't think you can create one (stack or heap) until Qt has been properly "initialized" via QCoreApplication. That may be why it does not appear to work.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            MrShawn
            wrote on last edited by
            #5

            A good test will be to call your DLL using a basic Qt app after you create your QCoreApplication. The first time I did this I tried to call my DLL from labview and it didn't work but when I tried to use it with my Qt application it worked fine.

            Not to mention debugging will also be easier with QDebug if you debug it that way.

            1 Reply Last reply
            0

            • Login

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