Using Qt and cmake to store static files into /usr/share - qt

I use Qt and cmake for my open source application, which is targeted at Windows and Linux currently. It is written in C++. Tarballs and debian packages can be generated using cmake, while InnoSetup is used for generating Windows setup packages.
I know Qt has QSettings for storing user-specific persistent data and is cross platform. I'm not asking about this.
I have some architecture-independent, purely static, non-user-specific data (basically some XML files that never change) which I want to install together with my executables.
From what I understand, in Linux, this should be installed into /usr/share/[application] or /usr/local/share/[application]. OTOH, in Windows, this should be installed in C:\Program Files\[application].
How do I use the install command in cmake to achieve this for Linux?
Does Qt have any cross-platform API to auto-detect the location of these files after installation, just like it does for QSettings?

I can't answer #1, but maybe QStandardPaths is what you're looking for for #2?

Related

Deploying pyqt application to Windows using pyqtdeploy

I would like to deploy for the first time my first app made with PyQt5. I found pyqtdeploy (link) to be probably what I need to do this for Windows and other platforms.
Anyway, I am following this tutorial, but, as I am completely new to deploying applications, I am not sure on one thing: do I need to download Qt for the target specific platform I need to deploy my app to? If so, am I supposed to use qmake from that Qt installation against the result of pyqtdeploy? For example: if I want to deploy to Windows, do I have to download Qt from here (and which version???)?
From the same tutorial page, this is not so clear, maybe it's obvious, but as I am a newbie in this, not for me.
No you don't need to download Qt.
When building your 'sysroot.toml' file, pyqtdeploy will download qt-everywhere-src and builds it from source.
In the built sysroot directory you can find qmake executable in "...\Qt\bin" (qmake.exe) depends on where your project files (sysroot.toml file) are.
For example if your host machine is Windows and C:\Users\username\Desktop\My_PyQtDeploy_Proj is your project folder which contains sysroot.toml, after building sysroot you can find qmake in "C:\Users\username\Desktop\My_PyQtDeploy_Proj\sysroot-win-64\Qt\bin\qmake.exe"

Installing Qt Creator with MinGW

So it looks like with Digia taking Qt over from Nokia, that it's quite a mess to get a few simple downloads.
If I now go to the downloads page (http://qt-project.org/downloads), I see that there's a single Qt Creator 2.6.2 download for Windows. When I download this and run the installation, it seems that MinGW is no longer packaged along with it.
I tried to install MinGW 4.4 separately and then add a toolchain, but nothing runs when I try to compile my CMake-based project.
I then came across the Nokia website that is offering Qt SDK 1.2.1; however it now looks that they require you to create an account to be able to download the installer.
Downloading the full set of Qt libraries is probably what is going to be suggested, but that's not the best idea, because I'm basically writing up an installation procedure for a CMake-based, open-source set of libraries that I've been working on for a while (http://tudat.tudelft.nl).
Users aren't happy with having to download all the Qt libraries, since we're not using any of them.
I've completely run out of solutions now (and mind you, this only seems to be a problem for Windows, since when I install Qt Creator on Linux and Mac, GCC auto-detection seems to work fine).
So, in short, does someone have a simple install routine to install Qt Creator and get it to work with MinGW to compile a CMake-based project?
Thanks in advance!
Kartik
PS: I know there are plenty of threads on Qt Creator + MinGW, but they all seem to be outdated now with the recent changes on both the Digia and Nokia websites.
I should add that the problem specifically is not that the toolchains can't be auto-detected under Windows. I've managed to get both MinGW and CMake auto-detected by Qt Creator by adding both to the system path. The problem is that when I then try to open the CMakeLists.txt file for my project, I can't select any generators.
Straight forward:
Install Qt Framework
Install MinGw
Install CMake
Install other stuff, e.g. git
Install Qt Creator
As you already mentioned, the chances are good that Qt Creator gets everything via auto detect. Nevertheless, you should check the Qt settings if everything is in place, e.g. the debugger.
The first time you open a cmake project, Qt Creator (should) ask for the tool chain to use. If you want to change the chain afterwards, delete the build files and cmake directories.
More details to Qt Creator and cmake: http://qt-project.org/doc/qtcreator-2.7/creator-project-cmake.html

How to install two versions of Qt and tell the application which to use?

I am developing an application in Qt, but using D language (with QtD binding). I've noticed that my app crashes with Qt 4.7.x, so I need to use Qt 4.6.2 instead. However in my system Qt 4.7.2 is installed. Unfortunately I neither make QtD work with the latest Qt versions nor (I'm afraid) count on QtD developers...
The only thing I need to make my application install in system Qt 4.6.2 libs and use it, but let all the other applications still use Qt 4.7.2. Is it possible? If it is, how to do it then?
The answer to your question is the version of Qt is determined by the qmake you use to generate your Makefile.
/opt/QtSDK/Qt-4.6.2/bin/qmake
/opt/QtSDK/Qt-4.7.3/bin/qmake
Each will use the library in the directory.
It is possible to install several versions of the library into one system, and all package managers (rpm, deb) support this out of the box.
These libraries will be just differently named. For example, if id do
ls /usr/lib/ | grep libcurl
on my system, I'll get:
libcurl-gnutls.so.3
libcurl-gnutls.so.4
libcurl-gnutls.so.4.2.0
libcurl.so.3
libcurl.so.4
libcurl.so.4.2.0
, so, different version of the same library happily live together.
All you need to do is to link against the desired version of QT library. You need to sepcify it in linker options (don't remember the exact option).

How to install a Qt application on a customers system?

I've got a Qt app that I need installed on a customers computer, which I can't assume has Qt installed on it. I'm on a Mac OSX and the computer I will be installing it on some Unix based system. I will be installing it myself so I don't need a GUI installation wizard or anything like that. Ideally I'd like to end up with a script or makefile, along with a folder of all the sources and necessary libraries, I just don't know where to start. References would be much appreciated, I haven't found anything useful after many google searches.
My question lies somewhere between these two:
Can you create a setup.exe in qt to install your app on a client computer?
Create Linux install for Qt application?
I don't need a full-blown install wizard (question 1), but I also won't have my machine at the installation site to just keep copying libraries until all dependencies are met (question 2). Basically I need to have everything on a CD ready to install when I get there. Thanks in advance.
There are two ways to install a Qt application on a system:
1 - You can compile Qt statically. This will allow you to deploy you app without any qt dependencies.
2 - You need to deploy your app with Qt librairy files you need (like qtcore.dll on Windows)
You will find all explications for each platform in the Qt documentation : http://qt-project.org/doc/qt-4.8/deployment.html.
To create installer you can use InstallJammer for Windows and Unix.
For MacOSX you need to create a dmg image. This is very simple. Read the following web page for help : http://www.wikihow.com/Make-a-DMG-File-on-a-Mac. By using apple script you can customize dmg (like an Application folder link into the dmg).
My preference for Win32 installer is NSIS.
Hope that helps!
Not sure why you want to avoid the install wizard. It can also help you create Uninstaller, desktop and start menu shortcuts, etc. As mentioned in the posts you refer to, you could use BitRock InstallBuilder (Nokia uses it for Qt Creator)
If you do not want to use a wizard and don't want to compile statically, then you can bundle Qt libraries in the same folder as the app and setup a shell script that sets the LD_LIBRARY_PATH to that directory

Qt create executable

Is there a quick, straightforward way to make a Qt application into an executable? I attempted to follow the instructions at http://doc.qt.digia.com/4.1/deployment-windows.html but have been unsuccesfull thus far; I'm unable to Any help would be much appreciated. Thanks!
I always use CMake to build Qt projects, it's easy, free and cross platform. Guide : Compiling Qt4 apps with CMake. CMake also come with CPack to easly make installer for Windows, Mac and Linux.
I agree with chmod700 about the Qt Creator suggestion, it's not my favorite IDE but it's still really nice and easy.
Do you mean an installer package? I assume you are able to compile, link, and run your app and you mean how do you package it up for others.
http://installbuilder.bitrock.com/ <-- special handling of Qt based projects but costs $
http://www.jrsoftware.org/isinfo.php <-- my personal favorite and it's free (can be rough to learn advanced features though)
Though if you mean how do you build your app, you may want to try the new Qt Creator (http://www.qtsoftware.com/products/appdev/developer-tools/developer-tools#qt-tools-at-a) which will setup build targets for you and really makes desktop Qt dev a snap. Also if you're still using 4.1, you can now use 4.5 under the LGPL on all platforms making it almost a no-brainer to upgrade.
I'm not sure if I understand your problem. Assuming you're using MinGW, it's really easy and quite straightforward:
get the Qt sources and unpack them to some folder (f.e. c:\Qt\4.5.0-static)
install MinGW. Make sure the MinGW executable folder is in the %PATH% variable.
open a cmd windows, go to the Qt sources and run configure -static. You can add other config options if you like to, but usually you don't need that.
when building Qt finished, go to your application sources, open a cmd window and run the qmake of your built Qt installation -- i.e. c:\Qt\4.5.0-static\bin\qmake in the example given above.
run make
you get a statically linked binary in the end (you might want to check it with Dependency Walker).
Doing the same using Visual Studio is pretty similar.
Or do you want to build dynamically and create an installer package?

Resources