I'm writing a Qt GUI application that works on Linux and Windows.
I have been able to deploy it on Linux and Windows with supporting shared libraries of respective platforms.
It runs absolutely fine on Windows and Linux except that controls do not appear as expected on Linux when I run the deployed binaries. e.g. QGroupBox is not at all seen and buttons and text label sizes are not as I had set.
If I run through Qt Creator on Linux, controls look alright.
Are there any specific files for UI which I need to deploy along with other required shared libraries to make sure that controls look fine across all platforms?
Thanks!
Try to run you program with parameters -style windowsxp. Also you should look at QStyle and its derivatives. In several cases you'll have to write platform-dependent code, like:
#ifdef Q_OS_WIN
label->setFrameStyle(QFrame::Panel | QFrame::Raised);
#else
label->setFrameStyle(QFrame::Box | QFrame::Sunken);
#endif
statusBar->addWidget(label);
Related
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
I'm developing a Qt Widgets application and due to compile performance issues, I started developing it in Linux Ubuntu instead of Windows. The problems is that, when compiled and run, the app appears with traditional Ubuntu style instead of Windows (7) style. Since the app is only for Windows, I'ld like to know how can I compile it inside Linux Ubuntu but making it appear with Windows style.
I tried using QApplication::setStyle(QStyleFactory::create("QWindowsStyle")); in main.cpp, without success. I guess the QtAssistant docs just aren't clear enough on how can I do this change. Any help will be appreciated.
Could you by any chance be using a Qt package that is compiled without the style? Can you try running QStyleFactory::keys() to verify that the style exists?
It can't be done, since the style's elements are rendered by Windows (or OS X), not by Qt. Qt's style implementation asks the OS libraries to provide bitmaps of those elements. If you wanted to, you could modify the style to use a disk cache for static items. You could then use the style on all platforms. The problem is that these OS-provided bitmaps are a part of the OS and thus non-redistributable.
The only plastform-specific style that at least used to be available everywhere was the old Windows 95 style, in times of Qt 3. I'm not sure what its current status is.
First check out put of QStyleFactory::keys()
then set the look by calling
qApp->setStyle("Windows");
This command will give you windows 98 look. If you want windows vista look you should configure qt sources with -style-windowsvista and rebuild all sources.
UPDATE
according to http://doc.qt.io/qt-5/qstylefactory.html#details qt style is not platform independent. So IT IS IMPOSSIBLE to have that native look in not windows platform. It's worth mentioning that in windows also Windows SDK itself is required in order to build sources of Qt otherwise your application will look like windows 98 in windows 7.
Is there a way to test the look of my UI on Windows or other platforms from my Linux machine? I'd like to have some idea of how it will look without having to rebuilding the project on a windows machine.
At the command line for your program you can specify the style:
http://qt-project.org/doc/qt-5.0/qtwidgets/qapplication.html#QApplication
-style= style, sets the application GUI style. Possible values depend on your system configuration. If you compiled Qt with additional styles or have additional styles as plugins these will be available to the -style command line option. You can also set the style for all Qt applications by setting the QT_STYLE_OVERRIDE environment variable.
In some older documentation it mentions:
Possible values are motif, windows, and platinum.
I just tried this on Windows 8 with Qt 4.8.4, and I got no change adding in "style=platinum" or any of the others, and apparently the build of Qt that I got did not come with the additional style plugins. So, build Qt with the additional styles, and then you can preview the look for other OS's.
Hope that helps.
I have been using Qt for a while on Linux and Windows. However, yesterday I picked up a new MacBook Pro so naturally I've been playing around to see if I could build my Qt apps on Mac.
I got pretty much everything working, however there is one problem : the file size of the resulting app bundle.
I am building my application like this:
qmake -spec macx-g++
make
macdeployqt my.app -no-plugins -dmg
The bundle and everything seem to work fine, but, the generated .app is 31.1 MB large and the .dmg is 13.6 MB!
Is this normal? Can I reduce this horrible size (on Windows, my installer for the same app with all the libraries is ~4 MB)?
If you are using the pre-built Qt libraries then the chances are that they are universal binaries with multiple architectures. For example, do $ file my.app/Resources/Frameworks/QtCore.framework/Versions/4/QtCore and you will see multiple architectures.
You can build your own Qt libraries with only the architectures that you want to support. You may wish to not support PPC because that is ancient; or if you are using a current Qt then you can make the decision of 32 bit vs 64 bit, but that's another question.
The problem is the size of the Qt dynamic libraries, as they must be part of your bundle.
These sizes can usually be reduced.
See the solution of How do I make apps smaller with qmake and macdeployqt on how to do this.
An excellent workaround would be a static build of Qt and linking your application against the static build. This usually is a very good idea as two applications installing Qt dynamically usually crash on Mac OS.
Your application will have with static build (from my exp.) approx. 10-20MB of size. Combined with the steps above, some more reduction might be possible.
I am working on an simple c++ application for my work that needs to run both on Windows and on Linux. When running on Windows it should display a simple GUI and when running on Linux it should use a textual UI (because the Linux computer don't use any GUI at all).
I was wondering if I could use Qt to write the app (since its cross platform) and replace the GUI usage on Linux with printouts to STDOUT using "#ifndef WIN32"?
Any other suggestions would be appreciated. The program reads some properties from an xml file and runs some tests according to those properties (access sockets, environmental vars etc.). My goal is to write a single project that would be statically compiled (to get an undependable executable) for each platform and avoid creating different projects.
Thank you.
It's certainly possible, but try to avoid #ifdefs as much as possible.
One approach is to isolate all the core features (data processing, networking etc...) in non-GUI classes. Then you write two sets of classes for presentation: one based on QWidgets, the other one that just does text input/output.
To wrap it up, use an #ifdef in you main() to select which "presentation" classes to use (and switch between QCoreApplication for non-GUI and QApplication for GUI).
Don't base that #ifdef on WIN32, use a custom variable. That way you can run and test both versions in the environment you're more familiar with.