Deploying a Qt application

  • Hi everyone,

    I've asked this question "here": but maybe I should have done it here in the first place, I hope that's okay for me to just copy it over here.

    So, total newbie to Qt here ;) Also, actually, to software development in general. I am a young mathematician who has just completed writing his first "scientific" program using Qt. I hope you'll forgive me if my questions sound silly (and I am aware that this has been asked several times, and that there's official documentation on this).

    I've designed this program using Qt Creator 2.5.0 (based on Qt 4.8.1 64 bits) on my PC under Linux (Ubuntu 12.04 64 bits). It works very well, but trying to figure out how to deploy the app for the past couple days has been a rude awakening. I didn't expect I'd be so lost and nowhere at this point.

    So, my project is not very sophisticated, it consists of approximantely 40 headers and 40 sources, a qrc containing a few png and html files, and I'm using a bunch of Qt classes which I guess are the most classical ones. Now I'd like to make this available in the simplest possible way for Linux, Mac and Windows users (mostly fellow mathematicians I guess, but those can ignore the first thing about computers). I'm tempted to give it up and ask people to install qt and compile my files, but I hope i change my mind.

    So, this is where I'm at now, please correct me if needed:
    -For Linux users, I should probably compile my program using static linking (?)
    Problem1: see afer.
    Q1: I guess I want to compile two versions, 32 and 64 bits? How well are they going to work on different distributions?
    Q2: Sould I make a deb file or something?

    -For Windows users,
    Problem2: I've tried to cross-compile the app for windows from my PC using wine and mingw32, following every tuto I could find on the web, but I never got it to work; there always seemed to be an error with the qmake.conf file or something. I've come to the conclusion that even though I don't have a PC with Windows on it, I should just find one (I guess I would need one anyway to test the app) and compile my source there.
    Q3: Suppose I manage to do that. Will my exe file work on all Windows computers?
    Q4: Should I try to create an installer (is it going to drive me crazy as well)?

    -For Mac users,
    Q5: I guess it's gonna be pretty much the same as for Linux case? (the advantage is, I do have a Mac at home).

    Okay, now here's my specific problem when I tried to build my project statically. First here's what I did:

    1. I downloaded the Qt4.8.3 sources and built them statically (strangely, the compiler(s) don't seem to care that I told them -prefix <some folder> (in the ./configure code line), it just compiled everything in the sources folder apparently (I can tell you what I did in more details if necessary).
    2. I changed the options in Qt creator to compile using the static version of Qt. I get a warning telling me "qmlviewer not installed" (don't know if that matters).
    3. Because I pretty much mixed different tutos read here and there, I tried to add "CONFIG+=STATIC" in the pro file, or adding some LIBS there, or... but that didn't seem to affect the result at all.
      What I get is a file that seemed to work at first: It was 15Mb instead of 1Mb previously, it no longer required the two Qt dependencies that it used to (checked that with ldd command line), and the program worked... apparently. First i notices in Qt Creator's Application output that I kept getting Qt errors: "*Gtk-CRITICAL *: IA__gtk_widget_style_get: assertion `GTK_IS_WIDGET (widget)' failed". Mmm... doesn't sound too good. Even worse, everything seems to work except my help menu that doesn't manage to show itself and makes the program pretty much freeze. And the output shows:
      X Error: BadDrawable (invalid Pixmap or Window parameter) 9
      Major opcode: 62 (X_CopyArea)
      Resource id: 0x0
      and sometimes QNativeImage: Unable to attach to shared memory segment. If you need to know, the help menu is a simple widget containing a QTextBrowser (and a couple buttons) that shows an html file with some png images.

    I'd really appreciate some help here, feeling a bit alone in the dark! Thanks in advance,


  • Moderators

    TL;DR, I have just skimmed your post, but here you go:

    On Linux, we prefer dynamic linking to OS-provided libraries. Be very careful about static linking in general - you need to use either GPLv3 or commercial license!

    Yes, this would be preferred. Or bundle the libs together with your app and apply some LD_LIBRARY_PATH magic.

    It's usually easier to just grab a Windows PC and compile it there. Yes, the binary will work on most Windowses available (you need to provide .dlls together with the exe file).

    Again, yes :) You don't have to, of course, but people will expect it to be available.

    You should use macdeployqt tool (in <Qt dir>/bin) to create a Mac package. It's rather straightforward and does everything for you automatically.

  • There exists in Qt Labs a project called "installer-framework": that can be used to create installers for various platforms. I think you should definitely try that on Windows.

    On Macs, standalone application bundles are preferred, and it is better to use macdeployqt as mentioned by sierdzio.

    Things get tricky with Linux. While it is good to build a .deb package, it only works on Debian-based distributions. And it is unrealistic to build packages for various package managing systems because there are "too many":

    If all (or at least most of) your users use Debian-based distros, it would be fine to use a Debian package. Otherwise I would suggest one of the following alternatives:

    a) Deploy under GPLv3 and statically link the libs.
    b) Deploy source codes. Most Linux distros come with compilers by default, and have easy access to Qt libs (it is even a good bet they have it already). Compilation wouldn't be that difficult for them if appropriate instructions are given.
    c) Deploy a dynamically linked program that requires dependency. Users can install Qt libs through the package managers of their own liking.

  • Thank you both!

    I'll try that installer-framework as soon as I get to work on a computer with windows. I'll try macdeployqt shortly.

    I already chose the GPLv3. So if I understand your suggestion uranusjr, I should provide the 3 options for Linux users. The problem is, for the moment, I'm stuck with that statically linked errors. [Edit: by the way, could you confirm that i need to build (statically or dynamically) two versions : 32 and 64bits]

  • Moderators

    Dynamic linking is easier, go that way if possible :)

    As for 32 vs 64 bits... depends. All 32 bit binaries should work on 64 machines without any problems, although it's not always the case. The reverse does not work, of course.

    So in theory it's enough to provide only the 32 bit binaries, and that is indeed what many companies do. On Mac, there is currently a strong push in the direction of 64b, but 32b apps still work flawlessly. On Linux, most providers have separate 64 bit and 32 bit packages available. It's really up to you.

  • Thanks again for your advice and precisions.

    I think what I'll do for Linux users (for the moment) is ask them to install the Qt framework and build my app, after all, I find that there's not a lot of disadvantages in doing that. Then in the near future, I might try the dynamic linking solution.

    Here's what I've written in my help file for the moment (if you feel like reading it you can tell me what you think):


    Unfortunately, deploying the application for Linux users seemed to be tricky. We decided to go for the simplest solution (at least for us): let you build the application from the sources. The disadvantage is that you have to download (~25Mb) and install (~112Mb on hard disk) the [link] Qt framework on your system (on the other hand, you will be able to build and to run Qt software in the future, such as KdE applications).

    Here are the different steps you need to follow:

    Install the package libqt4-dev (in Canonical repositories).

    Download the compressed folder [link] theApp.tar.gz and extract it somewhere in your hard disk.

    Open a terminal in that folder and type in:

    Note: The last step may take a minute. You may type instead make -j N where N is the number of processor cores that you have to speed things up.

    You're done! An executable file theApp was generated. Double-click on it or run it from the terminal: ./theApp

  • Moderators

    Looks good. Short, precise, gets the message across.

  • Thank you!

    I've successfully used macdeployqt, seems to work perfectly, it rocks.

    I'll try to use the installer-framework on Windows pretty soon. Out of curiosity, it's not worth using it for Linux?

  • Well, it's OK to use it for Linux. It's just that the Linux communities generally prefer shared libraries and package managers, and might feel uncomfortable using an external installer which messes with their OSs without their control.

    That said, you certainly can still provide an installer for Linux as an option at least.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.