views:

48

answers:

3

So far I have worked in the console and a few days ago decided to try the QT GUI. I downloaded the QT SDK , install it, adjust the location of QT and set up the PATH Environment Variable -> per the instructions on the site.

I opened a new Qt4 project in Code:: Blocks-in and it seemed that everything was OK. There is by default an example:

#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();
}

Started it an it was all OK.

After that I went to a tutorial on the official site and there is a final example. Some kind of simple game.I have done copy-paste of all .h and .cpp files and then put them in current project to see how it works but then problems arise.

Code::Blocks does not recognize some classes. For example :: #include QTimer : No such file or directory #include QRect : No such file or directory

I uninstall QT and re-installed and configured everything again but the problem does not go out.

These classes are not working nor in the default example ::

#include <QApplication>
#include <QFont>
#include <QPushButton>
#include <QTimer>     does not have real purpose , just for illustration

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();
}

ba\107\main.cpp|4|QTimer: No such file or directory| ||=== Build finished: 1 errors, 0 warnings ===|

I dont now how much classes don work properly , this is just some of them.

Not to reveal hot water for days on google looking for a solution, maybe for some of you , this is a bizarrely easy problem.

Thanks

A: 

Code::Blocks is only an IDE not a Compiler/Linker toolchain, so it is not Code::blocks that cant find the files, you have simply not configured your project to use them.

"No such file or directory" is a pre-processor error message; you still have to tell the compiler where to find your third-party header files. Moreover when it comes to linking, you will need to tell the linker where to find the libraries.

Clifford
I noted the location in opening project.Qt's location:C:\Qt\2010.03\qtHow other classes work ?
nik_02
@nik_02: Look at the build log to see exactly what parameters are being passed to the compiler and linker, you will see all the passed search paths for headers (-I<path>) and libraries (-L<path>). Also probably -l<lib> specifying which libraries are linked. Standard libraries and paths may be implicit - the GNU toolchain knows where they are already. I guess somewhere in the project settings there are fields to configure these, but I do not use Code::Blocks.
Clifford
A: 

Whenever you have an #include <blah> (with angle bracktes <>) the compiler looks in the default include path. You need to put the Qt include directory into the include path for your project. I'm not sure how this is done in Code::Blocks. It's probably somewhere in the project settings.

Cogwheel - Matthew Orlando
I noted the location in opening project. Qt's location: C:\Qt\2010.03\qt How other classes work ?
nik_02
Maybe this'll help? http://www.kerrywong.com/2008/07/12/codeblocks-settings-for-qt-development/
Cogwheel - Matthew Orlando
thanks , will read that article
nik_02
+1  A: 

You need to either spend time monkeying with the default include search path, or else just provide a more explicit path the header you want to include. I was able to reproduce your problem with Code::Blocks 10.05 (with bundled gcc) on Windows XP/32 and a previously installed Qt 4.6. Here is the slightly changed version of your code that I was able to build without any problem:

#include <QApplication>
#include <QFont>
#include <QPushButton>
#include <QtCore/QTimer>

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();
}

Take a look in your Qt install directory. You'll be able to see the include directory, and where all the headers are within it if you run into this problem with any other headers. It looks like the Code::Blocks projects sets up the QtGui directory as an include search path by default, which is why you didn't need to explicitly mention it for including QPushButton and whatnot.

wrosecrans
Thanks alot , that is solution
nik_02