Jumbala
Jumbala

Reputation: 4944

How to make Qt4 work using Code::Blocks in Linux Mint

I'm trying to use Qt4 using the Code::Blocks IDE. I'm running Linux Mint and I'm getting some errors. I looked around and found some people that had the same problem as me, but I can't seem to get their solutions working on my computer.

I installed Qt4 using the command

sudo apt-get install qt4-dev-tools

And when I type whereis qt4, I get qt4: /usr/lib/qt4 /usr/include/qt4 /usr/share/qt4

If I select "Create new Projet" in Code::Blocks and Select Qt4 project, it asks for Qt's location, which is $(#qt4) by default. If I click next, it says Code::Blocks doesn't know the "qt4" variable and gives me a prompt to set the base location, the include directory, etc.

Since I don't have any idea as to what I should be putting in there since nothing works (either it says "QTCore cannot be found in the specified directory", or the "lib" directory couldn't be found, etc.).

I tried what was posted on this forum: http://crunchbang.org/forums/viewtopic.php?id=18210, but it didn't solve my problem and I get the same errors.

In the "/usr/share/qt4" directory, there's a link to the "include" directory, but not to the "lib" directory.

I'm pretty new to Linux and all of this, so I'd like it if the answer was very detailed explaining what I did wrong / what I have to do.

Upvotes: 4

Views: 6793

Answers (1)

RTOSkit
RTOSkit

Reputation: 1201

  • Install the QtSDK
    As a first step I would advise you to download directly the QtSDK, from the project site here.

Note: You could also use the precompiled version for your Mint version, but in my personal experience, when working with external SDK, you have more independence in development, it also allows you to work freely with multiple versions of Qt simultaneously without move any dependence of your OS.

You can follow the graphics steps to install the SDK, I advise you to check the option "download source", later this is going to be used for debugging code, and if necessary will allow the recompilation of some classes.

Now your QtSDK is installed on the folder eg "/usr/local"

So, all references inside your IDE should refer to this location.

  • Install the C::B
    You can use the version available in "Software Manager"

  • Configure the C::B
    When we start a new project and asks the location of our SDK we indicate this directory
    /usr/local/QtSDK/Desktop/Qt/4.8.1/gcc
    Now the project is ready!

Note: "/usr/local" and "4.8.1" are variables depending on where and what version you have installed.


Is very likely that your build directory, is not correctly assigned in
"Settings->Compiler and Debugger->Toolchain ...->Compiler's Directory"
will be the default "usr" which should be replaced by "/usr/bin"

Now, when compiling with the standard project ".pro" and if your project has the requirement to use a "moc" tool strategy, the simplest way to do that, is use a customized Makefile, with all stages of compilation.

To learn how to make a customized makefile, you can read this answer.


And although I would advise again:

Although that CB is an optimal environment for working with wxWidgets, and C/C++ in general, I personally think that in the case of working with Qt, QtCreator provides a development environment more native and optimized to work with your projects QT.

Upvotes: 3

Related Questions