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 Dll created with Qt
Forum Updated to NodeBB v4.3 + New Features

Using Dll created with Qt

Scheduled Pinned Locked Moved General and Desktop
17 Posts 3 Posters 4.9k Views 1 Watching
  • 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.
  • E Offline
    E Offline
    epalmero
    wrote on last edited by
    #1

    I have what maybe an stupid question but for me is really important to decide wether I can buy a license of Qt or not. I need to provide some costumer with a Dll that contain mathematical method and some GUI stuff. I was thinking since Qt look native under windows and mac to use Qt for the GUI part. The question that I have is the following, will the user be able to call the DLL created with Qt from any other environment? Of course I will export the necessary functions and the all the QT GUI stuff will be handle by the DLL itself.

    Best and thanks
    Ernesto

    1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      Hi,

      Yes, you can call Qt-made DLLs from other programs.

      You can download and try the open-source version, to help you decide if you want to buy a commercial license: http://qt-project.org/downloads.

      If you want to use the Qt-made DLL to provide the GUI, have a look at this "StackOverflow thread":http://stackoverflow.com/questions/22289423/how-to-avoid-qt-app-exec-blocking-main-thread/22290909 which discusses this use-case. Note that Mac OS X has some restrictions on the GUI: Your DLL must inject the GUI code into the main thread.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • E Offline
        E Offline
        epalmero
        wrote on last edited by
        #3

        Thanks a lot I will download the non comercial one and give it a try. So far what I have listen from Qt is really good so if I can do it with the trial DLL I will then buy the commercial one.

        Thanks a lot

        1 Reply Last reply
        0
        • JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          You're most welcome :) Happy coding!

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          0
          • E Offline
            E Offline
            epalmero
            wrote on last edited by
            #5

            Dear All:

            Thanks for your help now I have a problem. I have create my DLL as a shared Library project. Now when I try to use the DLL in the other project I get the following error:

            Error 1 error C1083: Cannot open include file: 'QtCore/qglobal.h': No such file or directory c:\devel\ani\testapplication\opengl\erpmapviewdll\erp3dviewdll\erp3dviewdll_global.h 4 1 ConsoleApplication1

            I guess I need to provide that .h file and maybe many others as well as some .dll? Where I can find those file I am using Qt5.3

            Thanks a lot for the help
            Ernesto

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              It depends on how you wrote your code, your users may need to also install Qt

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • E Offline
                E Offline
                epalmero
                wrote on last edited by
                #7

                The whole Qt? I can't ask my users to install the whole Qt to be able to use the library that will not work for them. I thought I just need to distribute the dependency. I am making an small test

                @#ifndef ERP3DVIEWDLL_H
                #define ERP3DVIEWDLL_H

                #include "erp3dviewdll_global.h"

                #ifdef __cplusplus
                extern "C"
                {
                #endif
                ERP3DVIEWDLLSHARED_EXPORT void __cdecl init(void);

                ERP3DVIEWDLLSHARED_EXPORT void __cdecl close(void);
                

                #ifdef __cplusplus
                } /* extern "C" */
                #endif

                #endif // ERP3DVIEWDLL_H
                @

                that is my export function this is the erp3dviewdll_global.h

                @#ifndef ERP3DVIEWDLL_GLOBAL_H
                #define ERP3DVIEWDLL_GLOBAL_H

                #include <QtCore/qglobal.h>

                #if defined(ERP3DVIEWDLL_LIBRARY)

                define ERP3DVIEWDLLSHARED_EXPORT Q_DECL_EXPORT

                #else

                define ERP3DVIEWDLLSHARED_EXPORT Q_DECL_IMPORT

                #endif

                #endif // ERP3DVIEWDLL_GLOBAL_H
                @

                Thanks for any help

                1 Reply Last reply
                0
                • JKSHJ Offline
                  JKSHJ Offline
                  JKSH
                  Moderators
                  wrote on last edited by
                  #8

                  [quote]
                  @
                  #ifndef ERP3DVIEWDLL_GLOBAL_H
                  #define ERP3DVIEWDLL_GLOBAL_H

                  #include <QtCore/qglobal.h>
                  ...
                  @
                  [/quote]You included qglobal.h in erp3dviewdll_global.h -- this will force your users to require Qt headers.

                  Remove qglobal.h from erp3dviewdll_global.h and rewrite your code such that that you don't expose any Qt types in erp3dviewdll_global.h. Then your users won't need to install Qt.

                  Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                  1 Reply Last reply
                  0
                  • E Offline
                    E Offline
                    epalmero
                    wrote on last edited by
                    #9

                    Thanks a lot for all your help and support this work like charm. I test to put the .dll in the executable directory and then all work just nice.

                    Thanks a lot for your help
                    Ernesto

                    1 Reply Last reply
                    0
                    • E Offline
                      E Offline
                      epalmero
                      wrote on last edited by
                      #10

                      Hi:

                      Now I can link into the dll and if I just create a simple QWidget then I don't have any problem. But as soon as I try to do something else I get the following exception:

                      Unhandled exception at 0x77193129 (ntdll.dll) in ConsoleApplication1.exe: 0xC0000005: Access violation writing location 0x00000014.

                      This is my export function any help will be more than welcome

                      @void __cdecl init(void)
                      {
                      int argc = 0;
                      app = new QApplication(argc, NULL);
                      //render3DPanel = new Window();
                      render3DPanel = new testWidget();
                      render3DPanel->show();
                      app->exec();
                      }@

                      1 Reply Last reply
                      0
                      • E Offline
                        E Offline
                        epalmero
                        wrote on last edited by
                        #11

                        The application that use the DLL goes as follow:

                        @#include "stdafx.h"
                        #include "rendercommons.h"

                        int _tmain(int argc, _TCHAR* argv[])
                        {
                        init();
                        return 0;
                        }@

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          Hi,

                          AFAIK, argv can't be null. From the standard argv[argc] should return 0. So you still need a valid argv for that.

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          0
                          • E Offline
                            E Offline
                            epalmero
                            wrote on last edited by
                            #13

                            I have done that but still I get the same error. My guess is that Qt don't like something concerning the thread or something like that but I can't do anything inside the the Widget. I don't think I will be able to use Qt at all for what I am trying to do althouth I am surprise of that.

                            Thanks for the help
                            Ernesto

                            1 Reply Last reply
                            0
                            • JKSHJ Offline
                              JKSHJ Offline
                              JKSH
                              Moderators
                              wrote on last edited by
                              #14

                              Use a debugger to run your program. It will show you the sequence of calls that lead to the crash.

                              I have used Qt-based DLLs to create complex GUIs in a separate thread before -- it can be done.

                              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                              1 Reply Last reply
                              0
                              • E Offline
                                E Offline
                                epalmero
                                wrote on last edited by
                                #15

                                The problem is that if I use the DLL inside Qt then I don't have problem as soon as I try to use in another program outside Qt the same code simple explode?

                                Here is the code I am using a very simple one:

                                @#include "testwidget.h"
                                #include "vm/vec_mat.h"

                                testWidget::testWidget()
                                {
                                VM::Vec_INT error(1);
                                std::string filename = "C:/Temporal/OpenGL/errorfile.txt";
                                error(0) = 1;
                                error.write(filename);
                                }
                                @

                                This is the method that is cal outside the other application

                                @#include <QApplication>
                                #include "testwidget.h"
                                #include "window.h"
                                #include "rendercommons.h"

                                testWidget *render3DPanel;
                                //Window *render3DPanel;
                                QApplication *app;

                                extern "C"
                                {
                                void __cdecl init(void)
                                {
                                char arg0[] = "TextureRender";
                                char* argv[] = { &arg0[0], NULL };
                                int argc = (int)(sizeof(argv) / sizeof(argv[0])) - 1;
                                app = new QApplication(argc, &argv[0]);
                                //render3DPanel = new Window();
                                render3DPanel = new testWidget();
                                render3DPanel->show();
                                app->exec();
                                }

                                void __cdecl close(void)
                                {
                                    app->closeAllWindows();
                                    app->exit();
                                    delete render3DPanel;
                                    delete app;
                                }
                                

                                }@

                                if I remove this part from the testwidget:

                                @ VM::Vec_INT error(1);
                                std::string filename = "C:/Temporal/OpenGL/errorfile.txt";
                                error(0) = 1;
                                error.write(filename);
                                @

                                all work fine but as soon as I try to do anything inside the testWidget no matter what it simple explode. Any help will be really welcome beacuse I really like Qt and I want to use for a professional use but I need this to work really.

                                Thanks
                                Ernesto

                                1 Reply Last reply
                                0
                                • E Offline
                                  E Offline
                                  epalmero
                                  wrote on last edited by
                                  #16

                                  Hi All:

                                  I have maybe a solution in another way. I wanted to use the Shared Memory object that windows has. In this case I will be able to share the Memory between the 2 different processes. The question that I have is:

                                  Can I use the "SendMessage" of windows to communicate with a Qt process?

                                  Thanks a lot
                                  Ernesto

                                  1 Reply Last reply
                                  0
                                  • E Offline
                                    E Offline
                                    epalmero
                                    wrote on last edited by
                                    #17

                                    Hi All:

                                    I am sorry to comeback to this but after more that 2 weeks it look like I am still without any solution and I have try all what I have read on internet. I know that everybody said is possible to create a Qt DLL for a Non-Qt application but I don't arrive to do it. I get a very nasty error when trying to use the DLL which does not make any sense at all. It said it can't find the .exe of the application which is non sense because the .exe is there. I am posting here the direction to the Qt DLL I am doing. If someone can please help me with this and tell me what can be wrong I will really appreciate it. I really need to find a solution to this to be able to buy the commercial version of Qt since I have make all my development using Qt.

                                    Best and thanks for any help
                                    Ernesto

                                    https://www.dropbox.com/sh/8kmvfphazvpdtnl/AABZNoSh2IrAav_uUEsbpBNSa?dl=0

                                    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