Qt5 move qrc to DLL - c++

In my soluton I want to create second, helper app, which will be using the same resources as my main application. So I want do move all my .qrc files to DLL and use it in both apps on the same time.
I choosed dll format because in future my solution will contain shared functions which I will put in that dll.
How should I compile and attach DLL to use resources in both applications like standard .qrc files?

From the resource or build pointo f view there is no difference.
The .pro file of a DLL refers to its resource file exactly the same way as a .pro file of an application would.
The libraries resource "tree" can then be "imported" into the application with the QT_INIT_RESOURCE macro, see http://doc.qt.io/qt-5/resources.html#using-resources-in-a-library

Related

In Visual Studio 2012, how can one link resource file(.rc) with c ++ dll

I have to build a c++ .dll, where I need to show a dialog box in some
cases to interact with users. So I create a resource file (.rc),
integrate corresponding code in the dll project to show the dialog and
build the dll project with the resource file in VS2012.
Now the problem is when I load the dll in another test application and
call one of the method from dll which uses the resource file to show
dialogBox, this method returns
Error 0x715 is ERROR_RESOURCE_NAME_NOT_FOUND.**
The line inside the dll that returns the error is
DialogBox(HInstance, MAKEINTRESOURCE(IDD_INPUTDIALOG), NULL, NotifyUser);
It seems that my resource file (.rc) for DialogBox with id:
IDD_INPUTDIALOG is not linked or added in the dll. so it can not
find the dialog box resource.
Now if i add a resource file(.rc) in the test application with the same id as the resource file(.rc) in dll, the method call from dll uses the resource file(.rc) in test application , not the one in dll.
So is it the case that resource file is not liked or added in the dll?
Additional Info:
To build the dll with resource file, I use VS2012 and simply add the resource file in the project and build the project as dynamic link library (.dll).
Is it enough to add the resource file in dll, or do I have to set some
other flags or linker option to link the resource file (.rc) with dll?
Thanks in advance.
Considering the comment which confirms HInstance==NULL, it means the call is really DialogBox(NULL, MAKEINTRESOURCE(IDD_INPUTDIALOG), NULL, NotifyUser);. This looks for a dialog box in the EXE file of the process. That is the default location. To tell Windows to look elsewhere, you need the correct DLL instance.
To figure out your own instance from inside your DLL, call GetModuleHandle.

deploying c++/qml application - packing qml files into bin

I have a c++/qml applicaiton. My/custom qml files are packed in a resource file and loading well. My problem is that when I deploy my application I need to have in bin directory also all the QtQuick/QtQuick2 directories with all their content. Is there a way to have them packed/included in compiled .exe file? In theory I could include all in a resource file, but that seems like overkill.
Is there some way how to handle this?
You can use static linking to make a standalone executable:
https://wiki.qt.io/Build_Standalone_Qt_Application_for_Windows

Transforming an existant VC++ project using ITK or OpenCV library to a DLL , is it possible?

Is there any way to compile existant projects written in vc++ and libraries such as ITK or OpenCV into DLL files ? The purpose here is to call the functions implemented in these subprojects in a final software, using simple DLL files, instead of gathering tens of header and source files from different modules with DLLs and .lib files of the used libraries. So what are the steps I need to make to obtain the DLLs, and how should I interface the functions (the main functions also) of each subproject (module) in order to make them convenient for use in my final project ?
Thanks.
Make your existing project as dll project by changing the target format. or create a fresh dll project.
add existing dll in your target folder and lib as dependent input file in linker section of propeties of project.
3.You want to bundle all your dlls and libs into single dll or lib then you have download source code of each dependent and add in single project and build it as your own dll.

Qt - How to build a standalone app with OpenCV and Qt

I was able to connect Qtwith OpenCV and the my application is working properly. But now would like that my .exe file does not have any dependencies with .dll files. I would like be able to use my application in another computer without concerns.
I tried to search in several forums but i didnĀ“t find any solution to my problem.
Adding CONFIG += static to my .pro file is enough??
You need to add the CONFIG += static indeed, besides that you need to create a static build of OpenCV, Qt, and statically link it all into an exe.
I shared my setup here.
Just clone the repo and follow the instructions :)
check out bin2h. it can convert your dll file to a header file that you import into your project. you can then write out to file the generated header and then dynamically link it to your executable

How can I automatically load DLLs from a subdirectory?

In Visual Studio, you create a .dll project and it creates a .dll and .lib files. You link statically to the .lib, and if the .dll is in the same folder as the .exe, everything works.
I suspect that everything would also work if the .dll was in System32 or any other PATH folder (confirm or correct, please).
But here's the question: I want my exe to find the .dll in ./DLLS/ folder, that is, if my exe is in ....../MyApp/MyApp.exe then it should look for the .dll in ...../MyApp/DLLS/MyDll.dll. I DO NOT want to include the DLLS folder in path. Is there any way I can do this?
Please note that I do not wish to use LoadLibrary explicitly, so I can't specify the path there.
Thanks in advance for any help.
Here is the default sequence which Win32 applications go through when looking for a DLL:
http://msdn.microsoft.com/en-us/library/7d83bc18(VS.80).aspx
So according to this, another approach might be to call SetCurrentDirectory or SetDllDirectory. But in order for this to work you have to use the Delay Loaded Library functionality (you specify that in Project Settings in Visual Studio). Delay loaded library means that the DLL is loaded only at the moment when the program needs it, not automatically at the programs' startup.
You could use SetDllDirectory for this. The loader will use the additional directory you specify when loading libraries. There can only be one additional directory, however, so you need to make sure that there aren't other calls to this at a later point in your application, otherwise the directory you specify will be ignored.
If that API does not allow relative directories (I'm not sure), you could always call GetModuleFileName with a NULL first parameter to get the file name of the currently executing program. With a little string manipulation, you can get the absolute path to your DLLs folder.