PDA

View Full Version : Code::Blocks and QT4



RemmyLee
February 6th, 2008, 03:30 AM
Here's a little walkthrough to using QT4 with Code:Blocks.


What this assumes:

1. You have QT4 and Code::Bocks installed.
2. You know how to use qmake.


Step 1:
You're going to need a special little tool known as qt-prebuild (see attachment). Build it and place somewhere easily accessible.

Step 2:
Here is the setup:

http://farm3.static.flickr.com/2343/2244967963_bfe9b827fa_o.png
http://farm3.static.flickr.com/2248/2244968051_3dfcec3183_o.png
http://farm3.static.flickr.com/2175/2245762734_d32b1c8e26_o.png
http://farm3.static.flickr.com/2108/2245762818_f94ce96444_o.png
http://farm3.static.flickr.com/2010/2244968325_da2b0569d3_o.png
http://farm3.static.flickr.com/2086/2244968413_f37eba5345_o.png

Step 3:
Compile.

Remember to copy your setup over to Release as well and have fun coding!

sspeed
April 27th, 2008, 08:09 PM
I manage to get the file but the pictures are not available anymore. Is there any way you can post them again. Thanks

nilankaraja
August 5th, 2008, 07:49 PM
I had the same problem. went through various forums and found this answer. The wizard now works and generates a compilable project. The paths are given in the picture.

I installed the following packages using the synaptic package manager

libqt4-core libqt4-gui libqt4-debug libqt4-dev qt4-designer qt4-dev-tools qt4-doc

should work

rquin
August 25th, 2008, 07:24 PM
I set my Global Variables the same as nilankaraja did, as per the screenshot. Unfortunately I get the following errors:
/home/ronnie/Programming Tests/QT TEST Thing/main.cpp|1|error: QApplication: No such file or directory|
/home/ronnie/Programming Tests/QT TEST Thing/main.cpp|2|error: QFont: No such file or directory|
/home/ronnie/Programming Tests/QT TEST Thing/main.cpp|3|error: QPushButton: No such file or directory|
/home/ronnie/Programming Tests/QT TEST Thing/main.cpp||In function ‘int main(int, char**)’:|
/home/ronnie/Programming Tests/QT TEST Thing/main.cpp|7|error: ‘QApplication’ was not declared in this scope|
/home/ronnie/Programming Tests/QT TEST Thing/main.cpp|7|error: expected `;' before ‘app’|
/home/ronnie/Programming Tests/QT TEST Thing/main.cpp|9|error: ‘QPushButton’ was not declared in this scope|
/home/ronnie/Programming Tests/QT TEST Thing/main.cpp|9|error: expected `;' before ‘quit’|
/home/ronnie/Programming Tests/QT TEST Thing/main.cpp|11|error: ‘quit’ was not declared in this scope|
/home/ronnie/Programming Tests/QT TEST Thing/main.cpp|12|error: ‘QFont’ has not been declared|
/home/ronnie/Programming Tests/QT TEST Thing/main.cpp|12|error: ‘QFont’ was not declared in this scope|
/home/ronnie/Programming Tests/QT TEST Thing/main.cpp|14|error: ‘QObject’ has not been declared|
/home/ronnie/Programming Tests/QT TEST Thing/main.cpp|14|error: ‘clicked’ was not declared in this scope|
/home/ronnie/Programming Tests/QT TEST Thing/main.cpp|14|error: ‘SIGNAL’ was not declared in this scope|
/home/ronnie/Programming Tests/QT TEST Thing/main.cpp|14|error: ‘app’ was not declared in this scope|
/home/ronnie/Programming Tests/QT TEST Thing/main.cpp|14|error: ‘SLOT’ was not declared in this scope|
||=== Build finished: 15 errors, 0 warnings ===|



I checked /usr/inclue/qt4 and all the headers are there in their given directories. Like qapplication.h is under /usr/inclue/qt4/qt. I changed it to that direct path to test, but that gave the same error. I've done the silly things, like test the includes with lowercase, with .h at the end, by trying to include the full path etc. :(

This is the code I'm trying to compile:
#include <QApplication>
#include <QFont>
#include <QPushButton>

int main(int argc, char* argv[])
{
QApplication app(argc, argv);

QPushButton quit("Quit");

quit.resize(75, 30);
quit.setFont(QFont("Times", 18, QFont::Bold));

QObject::connect(&quit, SIGNAL(clicked()), &app, SLOT(quit()));

quit.show();

return app.exec();
}

Thanks in advance for any help :)


*As per http://wiki.codeblocks.org/index.php?title=Global_compiler_variables the Base should be /usr, the lib should be /usr/lib and the include should be /usr/include. Not that it works, haha.

bfhicks
August 25th, 2008, 08:11 PM
I'm not sure b/c i'm at work. But do you have to specify your project to link to the correct objects? I am not sure if that's what nilankaraja is saying, but on my windows version here @ work, I have to go into project build options and specify which libraries I want to link with it -- in your case the qt library.

Project Properties | build options | linker settings (tab)


--not sure if this is what you do on the linux distro as i'm using the windows version

rquin
August 25th, 2008, 09:17 PM
I reviewed the build options and the global variables (See Screens). Thanks for looking at this :)

Unfortunately I still get the error message :(

shulong
August 30th, 2008, 07:32 AM
You can select item.

1. select "project" -> "build options" for add incldue path.

2. select "search directories" -> "compiler"

3. select "add" to add include file.

e.g.
/usr/include
/usr/include/qt4
/usr/include/qt4/Qt
/usr/include/qt4/QtCore
/usr/include/qt4/QtGui
etc...

Then Code:Blocks will find qt incldue file.

Portable_Jim
December 30th, 2008, 04:45 AM
You can select item.

1. select "project" -> "build options" for add incldue path.

2. select "search directories" -> "compiler"

3. select "add" to add include file.

e.g.
/usr/include
/usr/include/qt4
/usr/include/qt4/Qt
/usr/include/qt4/QtCore
/usr/include/qt4/QtGui
etc...

Then Code:Blocks will find qt incldue file.
Thanks a lot. It works, however I found your instructions a bit hard to follow / unclear / confusing.



You should be in a project (just to make it clear for newbies)
Right click on the project (The thing right under workspaces)
Choose Properties
Under "Project settings" (first tab and probably selected by default) click on "Project's build options".
Click on "Search directories"
Click on "Add" and put in "/usr/include/qt4" (or wherever the installation of Qt is - by default on Ubuntu it is put here.)

(Attached image helps with instructions)

If the program will still not compile, and is producing errors (along the same line) then you may need to add the extra directories

e.g.
/usr/include
/usr/include/qt4
/usr/include/qt4/Qt
/usr/include/qt4/QtCore
/usr/include/qt4/QtGui
etc....
The button next to the filename you add is the browse. use that to find the other folders by first putting in "/usr/include/qt4", then click on the button. This will show you some of the folders mentioned above, plus more.

Bombenbach
September 29th, 2010, 01:34 PM
None of the proposed solutions actually worked for me (Lucid 10.04 and Code::Blocks from the Lucid repos). The following solution, however, works great!

http://www.amazing-tutorials.com/qt/configure-qt-with-code-block/