Code::Blocks
October 30, 2014, 01:10:29 pm *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: The new Release 13.12 is out! You can download binaries for windows, mac and many major linux distros from  http://www.codeblocks.org/downloads/26 .
 
   Home   Help Search Login Register  :: WebsiteWiki  
Pages: [1]   Go Down
  Send this topic  |  Print  
Author Topic: codeblocks+qt 4.2.1  (Read 5643 times)
NGF
Newcomer
*
Offline Offline

Posts: 5


« on: November 16, 2006, 05:16:27 pm »

Good evening.

I have codeblocks 1rc2 installed on windows xp home and qt 4.2.1 opensource installed too. I am trying to write a simple application using qt forms but I don't know how to do that. I tried the "QT Application" inside codeblocks but when I try to run it by pressing F9 it says:

Code:
main.cpp:1:21: qstring.h: No such file or directory
main.cpp:2:26: qapplication.h: No such file or directory
main.cpp:3:25: qpushbutton.h: No such file or directory
main.cpp: In function `int main(int, char**)':
main.cpp:7: error: `QApplication' undeclared (first use this function)
main.cpp:7: error: (Each undeclared identifier is reported only once for each function it appears in.)
main.cpp:7: error: expected `;' before "app"
main.cpp:8: error: `QPushButton' undeclared (first use this function)
main.cpp:8: error: expected `;' before "quit"
main.cpp:10: error: `quit' undeclared (first use this function)
main.cpp:11: error: `QFont' has not been declared
main.cpp:11: error: `Bold' undeclared (first use this function)
main.cpp:11: error: `QFont' undeclared (first use this function)
main.cpp:12: error: `QObject' has not been declared
main.cpp:12: error: `clicked' undeclared (first use this function)
main.cpp:12: error: `SIGNAL' undeclared (first use this function)
main.cpp:12: error: `app' undeclared (first use this function)
main.cpp:12: error: `SLOT' undeclared (first use this function)
main.cpp:12: error: `connect' undeclared (first use this function)

the generated code is

Code:
#include <qstring.h>
#include <qapplication.h>
#include <qpushbutton.h>

int main(int argc, char **argv)
{
    QApplication    app(argc, argv);
    QPushButton     quit("Hello World!");
   
    quit.resize(300, 40);
    quit.setFont(QFont("Arial", 18, QFont::Bold));
    QObject::connect(&quit, SIGNAL(clicked()), &app, SLOT(quit()));
    quit.show();
   
    return app.exec();
}

Can you help me to set up QT? I don't like win api!
Logged
sethjackson
Guest
« Reply #1 on: November 16, 2006, 06:41:02 pm »

Yup upgrade to a nightly build. Wink

Also your includes are wrong. Take the .h off.
Logged
iw2nhl
Advanced newcomer
*
Offline Offline

Posts: 116

BASIC, C, C++, Qt, bash


« Reply #2 on: November 16, 2006, 07:41:50 pm »

As far as I know in Qt 4 the includes must be in one of the forms like:
#include <QApplication>
or
#include <qapplication.h>
While in Qt 3 only the last form is accepted.

May be you don't have the qt path correctly set?
Logged
NGF
Newcomer
*
Offline Offline

Posts: 5


« Reply #3 on: November 16, 2006, 09:36:40 pm »

I tried taking off ".h" but no solution. Could you tell me more about setting qt path correctly? I am beginner to codeblocks and to C++. I am going to try nightly build.
Logged
NGF
Newcomer
*
Offline Offline

Posts: 5


« Reply #4 on: November 16, 2006, 10:21:10 pm »

I tried nightly build. I started a new QT project and in the wizard I selected the qt folder with the lib and include subfolders. I tried to run the project and I got a error saying that cannot find QtCore4.dll file. When I press I get a dos window saying

Process returned -1073741515 (0xC0000135)   execution time : 2.938 s
Press any key to continue.

Any solutions???

Thank you in advance!!
Good night
Logged
Shakes
Advanced newcomer
*
Offline Offline

Posts: 11


AKA: A Nud3 L3mming


« Reply #5 on: November 17, 2006, 02:14:46 am »

When forming a QT4 project, it will ask you to fill in the compiler variable $(#qt), clicking next will bring up the "Global Variable Editor". Here in the Base fill in the QT directory location, in the include area the whole QT directory location with include suddir and the same for the lib part filling it in with the lib location.

Click close (Bug - it will complain its not a valid path, ignore it. It should be correct as long as QT is in the directory you've set). Then next (change these settings to your liking), then finish.

Once this is done, go into project properties and under build options and check that the Linker and Directories areas have (becareful to check what build settings, Debug/Release or the Project, that you're checking) the:
Code:
$(#qt.include)
$(#qt.include)\GtGui
in the include area (Note that \ can be replaced with / in WinXp and up. I'd replace it with / if in windows to make the project compatible with linux).
The:
Code:
$(#qt.lib)
in the Libraries Directory area.
The:
Code:
QtCore4
QtGui4
in the Linker part. Note here that you may need to add other libraries depending on what classes u use (Assistant docs show the module name under the class names). Important: Windows libraries have 4 appended to them in QT win, in Linux the "4" is NOT present (I dont know if the project wizard is smart enough to spot that).

Finally you can bypass the whole wizard thing by just creating a console app and creating a Global Variable like above and using the string mentioned above in the relevant sections.

If your app compiles and links, but "Cannot find QtCore4.dll" or in Linux "QtCore.so.x not found" when running, then in linux u config the dynamic linker:
Edit your /etc/ld.so.conf file (using admin/su/sudo) and add the Qt lib dir (full path) to it save and then run ldconfig using su again.
In other words (in Debian based linux's):
Code:
sudo nano /etc/ld.so.conf
then edit the file and save, then
Code:
sudo ldconfig
Windows: I just copy the dlls to the same directory as the app I created (messy but works Tongue ). The names of the dlls will be the same as the libraries listed in the Linker part.

Hope that Helps
Peace Out
Shakes
Logged

Platform: Ubuntu 6 LTS AMD64 / Win x64 XP
Compilers: g++ / MinGW / .Net
Blitz ++ / Qt / VTK (Soon)
MortenMacFly
Administrator
Lives here!
*****
Offline Offline

Posts: 8680



« Reply #6 on: November 17, 2006, 08:49:44 am »

I got a error saying that cannot find QtCore4.dll file.

When I press I get a dos window saying Process returned -1073741515 (0xC0000135)   execution time : 2.938 s
O dear, when did you say you started programming? A minute ago?! ;-)

Anyway: In the path of your executable (the C::B output folder of your project) is the exe (application) that is going to be launched. Somewhere in another path (where you have installed the QT SDK) is the QtCore4.dll file. You see: You have to bring them together to get a working executable, becasue the executabel *depends* on that DLL. Now you have basically four ways:
1.) Copy the DLL (I believe this is not the only one that is required by your application, just the first that's missing) to the folder of your executable
2.) Extend the PATH environment to the folder, where the QT DLL's are located
3.) Copy the QT DLL's to a folder that is in the path (e.g. %WINDOWS%\system32
4.) Link statically (which maybe the worst option as the application gets a *lot* bigger)

Choose from and try to understand why this is.

In addition: The console window only opens if you run the debug window. In there usually debug output is shown if you have implemented that in *your* application. What you see there is the return code of your application saying an error has occurred. This is true, as the major QT DLL that provides basic functionalities could not be found.

With regards, Morten.
Logged

Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: http://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: http://wiki.codeblocks.org/index.php?title=FAQ
NGF
Newcomer
*
Offline Offline

Posts: 5


« Reply #7 on: November 17, 2006, 03:35:49 pm »

I tried the third and guess what-it worked!!! I got a small window with a button saying "Quit". It worked fine. Could you give me some help in creating the gui. How do i create radiobuttons, buttons? I know nothing!
Logged
iw2nhl
Advanced newcomer
*
Offline Offline

Posts: 116

BASIC, C, C++, Qt, bash


« Reply #8 on: November 17, 2006, 05:02:04 pm »

Could you give me some help in creating the gui. How do i create radiobuttons, buttons? I know nothing!

Qt has an excellent documentation with a lot of fully documented examples.
You can create the GUI in 2 modes:
1) using QtDesigner
2) coding it
The first way is easier and more intuitive and is documented in the section "Qt Designer Manual".
The second way is a little more difficult, but gives you full power and more functions. See "Qt Examples" and start with the "Qt Tutorial" which brings you from a simple "Hello world" window to a full game!
A mixed way exists too: draw the basic GUI with QtDesigner, compile and let Qt generate the C++ code for the GUI, then copy the generated code to your files and start from that. The generated code is very good.
Logged
NGF
Newcomer
*
Offline Offline

Posts: 5


« Reply #9 on: November 17, 2006, 05:03:57 pm »

Ok! I will try it!
Logged
iw2nhl
Advanced newcomer
*
Offline Offline

Posts: 116

BASIC, C, C++, Qt, bash


« Reply #10 on: November 17, 2006, 05:14:40 pm »

Happy coding and enjoy Qt!
Logged
ychking
Guest
« Reply #11 on: November 22, 2006, 12:42:03 pm »

i have the same question with NGF Sad
how NGF soluted it,what is nightly build?
thank u
Logged
Alturin
Advanced newcomer
*
Offline Offline

Posts: 79


« Reply #12 on: November 23, 2006, 07:12:16 am »

*cough* check this board *cough*
Logged
Pages: [1]   Go Up
  Send this topic  |  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.20 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!