Using Dll created with Qt
-
It depends on how you wrote your code, your users may need to also install Qt
-
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
-
[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.
-
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 -
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();
}@ -
The application that use the DLL goes as follow:
@#include "stdafx.h"
#include "rendercommons.h"int _tmain(int argc, _TCHAR* argv[])
{
init();
return 0;
}@ -
Hi,
AFAIK, argv can't be null. From the standard argv[argc] should return 0. So you still need a valid argv for that.
-
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 -
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.
-
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 -
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 -
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
Ernestohttps://www.dropbox.com/sh/8kmvfphazvpdtnl/AABZNoSh2IrAav_uUEsbpBNSa?dl=0