Where are QT platform dlls supposed to go? - qt

I have created a DLL that uses some functionality from QTWebKit, that I then access through JNA on the java side. On my machine (which QT is installed on obviously) it works fine. When I move it to another machine to to test it that does not have qt installed I get:
Failed to load platform plugin "windows". Available platforms are:
My google fu as pointed me to the fact that I need to also include platform DLLs, namely qwindows.dll and qminimal.dll. According to the QT5 documentation in Deploying an Application on Windows it sounds like when deploying an executable it would be in a folder called platforms in the save directory as the executable.
In contrast to user plugins, Qt plugins have to be put into
subdirectories matching the plugin type. As we want to deploy the
windows platform plugin it has to be put into a "platforms"
subdirectory.
That leads me to my dilemma. I have a dll, not an executable. So I have no clue where to put the platform folder. I have tried to place it in the same directory I am executing my test application, but that did not work.
So where do I place the platform directory in order for QT to be able to find it?
Edit:
Since I have not had much feedback, maybe there is a better way to word/approach this question.
How do I tell QT where to find the platform DLLs?
It seems like there has to be a way to accomplish this. When I run it on my machine, it ends up looking in C:\Qt2\Qt5.0.2\5.0.2\msvc2012_64\plugins\platforms. So it seems there m

I have found two possible solutions for the scenario that you need to create a QApplication inside a DLL or library (basically different from the normal create Qt application that has an exe).
The easiest solution is to set the system environment variable QT_QPA_PLATFORM to the folder that you expect the platforms to be located at. I did not like this solution do to the fear that it could interfere with other applications installed on the end system.
The next solution is to take advantage of the command line parameters that a normal QT application would use. In a normal Qt application QApplication would be created in your main similar to:
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
//other code
return app.exec();
}
Well we have to create argv and argc anyway at this point so use that to our advantage.
char *argv[] = {"YourAppName","-platformpluginpath", "C:/your/path/to/dll/folder", NULL};
int argc = sizeof(argv) / sizeof(char*) - 1;
QApplication app(argc, argv);
NOTE: Even now googling for -platformpluginpath I could not find any information for it. Or information on what other command line parameters may be available to use with QT. I found it by digging into the QT source code while looking for a solution. So if anyone happens to have a link to a resource with that information it would be handy to leave a comment with it.

http://msdn.microsoft.com/en-us/library/windows/desktop/ms682586(v=vs.85).aspx#standard_search_order_for_desktop_applications
When you are running your program in Qt, it adjusts the environment variables to add some stuff on to your path.
The default "path" that your dll is aware of when it is being ran depends on the exe that loads it, and its working directory, its application directory, etc. If you test program that is loading your dll, is in the same folder as the dll, you probably just need to put qwindows.dll in "./platforms/".
You also should check into this function:
http://qt-project.org/doc/qt-4.8/qcoreapplication.html#setLibraryPaths
http://qt-project.org/doc/qt-4.8/qcoreapplication.html#libraryPaths
Hope that helps. Good luck.

Related

How to run Qt5 applications with a specific translation?

I'm adding translations to a Qt5 project and I'd like to run the application with a specific translation to test it with a different language. I already have the .ts files and generated the corresponding .qm files. However, I found no information on how to run Qt5 applications with a specific translation. I've found some references based on setting the LANG environment variable in linux but I had no success.
Does anyone know if it's possible to run a Qt5 application with a specific language? If it is, what's the best way to set which language is used by a Qt5 application?
Add TRANSLATIONS += lang_ua.ts to your .pro file. Then add to your main()
QApplication a(argc, argv);
QTranslator translator;
translator.load("lang_ua");
a.installTranslator(&translator);
For changing translation load another file in translator.load().
All your translations will be read with QObject::tr()

Qt error with reMarkable tablet app

I have a reMarkable tablet , which I mostly love except for the lack of linux support (surprising given it is a linux-based OS). However, I've managed to find a version of a linux application that is now unofficial. This github is actually a Qt docker app, but if you look in the code for the 'Dockerfile' you can find where to download the app, which is apparently still on the server even though there's not a link from the main web page. Anyway, I downloaded it and got it mostly working, figuring out a few dependencies based on same Dockerfile code. But, I can't seem to get file dialogs to work, which is the main reason for using the app.
The error I get is:
ERROR: No native FileDialog implementation available.
Qt Labs Platform requires Qt Widgets on this setup.
Add 'QT += widgets' to .pro and create QApplication in main().
I'm not a Qt developer, so I'm lost. I'd love to get this to work. Thanks.
In the .pro file of you project you should add this line QT += widgets
or just add widgets to the line with QT += ...
Qt can use native file dialogs on some platforms, and will fall back to its own implementation if none is available. But that requires that the application is built including the QtWidgets module, and using a QApplication.
If you don't have the source code of the app and a possiblity to rebuild it, there's no chance to fix this from a binary

Integrate QT GUI DLL into my application

please note that I am not a native in English. sorry for any mistake.
I am very new to QT(just started yesterday) and have only few experiences with MFC.
I want to know how to integrate QT GUI DLL into non QT application.
I made this QT GUI DLL from the wizard: I simply chosen QT Gui Application and in .pro I changed "TEMPLATE = app" to "TEMPLATE = lib", as well as changing source code.
I attached source code here, you may looks at it.
http://cfile208.uf.daum.net/attach/025A524151C3E65D1B5E63
in the zip file, sources in folder "gui" does creating GUI DLL.
sources in folder "main" actually loads DLL and try to call the function in DLL.
they compiles well, but it seems they do not work. it gets an error called "there should be only one application object" when I start main.exe
What is the problem?
Don't create QApplication object in your library. There must be only one QApplication object, and it's already created by the main app.
If you need to access QApplication object from your library, use qApp macro to obtain a pointer to the QApplication.

Modify Qt's shared library code while application starts

I'm trying to create some kind of a server which allows me to start Qt's applications on remote machine via web browser.
I'm wondering it is possible to change/hide some symbols from Qt library (I thought about QApplication or QCoreApplication) without making any changes in code of application (I assume that it is already compiled and uses Qt shared library) and compiling my whole tailor-made Qt libs?
The reason why I need to do this is because I want to install my own specific EventFilter to QApplication and also be able to push my own created events to Qt application.
It also would be great if the solution could be used on all platforms :D
P.S. I know that it will not be possible I could subclass QApplication and modify all Qt apps to use my derived class but I would like to do this more craftily. ;-)
The tool GammaRay does all kinds of injecting code into Qt methods at runtime to attach and debug running Qt applications. You might want to have a look at its code base to see how it is done.

Import Qt resources when are main.cpp and GUI classes in dependend static lib project,

Scenario:
I have MSVC2005 with the Qt Visual Studio AddIn installed. In my solution there is a project A consisting of multiple plain C++ code modules, which is built to an executable A.exe. Project A does not contain a .cpp file with a main(), but has a dependency on a project B.
B is a Qt project built as a static lib. It consists on multiple GUI classes an a Qt-typical main.cpp(). Compiling an linking A and B works like a charm and I have a Qt-application. I made some forks of A (Afork1, Afork2, etc.) that all share the same interface to the GUI but have different customizations of the underlying business logic. I can batch build A.exe, Afork1.exe, ..., etc. and they all will have the same GUI, which is pretty neat.
Problem:
In B there is a .qrc file with multiple images, icons, etc. that are used in the GUI. The GUI classes are crafted with Qt Designer and I added the ressources to the GUI widgets. After building and running A.exe I cannot see these icons and images, the space for them is reserved in the widgets but not filled with the content. I guess, the ressources are not linked into the executable. Is there a way to ensure the linking of ressources that are part of Qt static lib project?
You need to initialize the resources explicitly. From the Qt docs:
If you have resources in a static
library, you might need to force
initialization of your resources by
calling Q_INIT_RESOURCE() with the
base name of the .qrc file. For
example:
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Q_INIT_RESOURCE(graphlib);
...
return app.exec();
}

Resources