1. Introduction
2. Kdevelop and QtDesigner
3. Quanta
4. About
This howto is based on GNU/Linux Ubuntu 7.10 (Gutsy Gibbon) but can probably be applicated to many other GNU/Linux distributions.
2.1. Brief description
This tool can be used to develop in:
C
C++
etc.
This chapter is based on Kdevelop v3.5.0 and QtDesigner 3.3.7.
2.2. Installation
The development environment can be easily installed by calling:
sudo apt-get update
sudo apt-get install kdevelop kdevelop3-doc autoconf automake g++ libqt3-headers libqt3-mt-dev kdelibs4-dev
2.3. Creating a GUI in C++
2.3.1. Create a new project
click on menu: Project -> New Project
select: C++ / KDE / Simple KDE application
enter application name: test
click on next
click on next
click on next
click on next
click on finish
2.3.2. Specify executable kind
By default, the executable is built with debug information.
To build an executable without debug information:
click on menu: Project -> Build Configuration
select: optimized
2.3.3. Build the project
click on menu: Build -> Run automake & friends
click on menu: Build -> Run configure
click on menu: Build -> Build Project (or press F8)
click on menu: Build -> Execute Program (or press SHIFT + F9)
2.4. Replacing main window with custom dialog
2.4.1. Name convention
You have to differentiate between the form file name (the .ui file) and the class name.
In our example, the form file name is
mytestdlg
and the class name is
MyTest
If you accidentally use the same name (in this case mytest for form file name and MyTest for class name), you will get errors like these:
test/src/mytest.h:27: error: expected class-name before "{" token
test/src/mytest.h:28: error: ISO C++ forbids declaration of "Q_OBJECT" with no type
test/src/mytest.h:30: error: expected ";" before "public"
test/src/mytest.h:35: error: expected `:' before "slots"
test/src/mytest.h:38: error: expected primary-expression before "protected"
test/src/mytest.h:38: error: ISO C++ forbids declaration of "slots" with no type
test/src/mytest.h:38: error: expected ";" before "protected"
test/src/main.cpp: In function "int main(int, char**)":
test/src/main.cpp:50: error: no matching function for call to "KApplication::setMainWidget(MyTest*&)"
/usr/share/qt3/include/qapplication.h:122: note: candidates are: virtual void QApplication::setMainWidget(QWidget*)
test/src/main.cpp:51: error: "class MyTest" has no member named "show"
make[2]: *** [main.o] Error 1
generating mytest.moc (moc)
moc: mytest.h: No such file
make[2]: *** [mytest.moc] Error 1
make[2]: Target `all' not remade because of errors.
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2
*** Exited with status: 2 ***
2.4.2. Remove main window
On the Automake Manager (right side of the IDE) expand:
test (Program in bin)
to see all the source files composing the project. Then:
right click on test.cpp file
select: Remove
select: Also remote it from disk
On the Automake Manager (right side of the IDE) expand:
(Header in noinst)
to see all the header files composing the project. Then:
right click on test.h file
select: Remove
select: Also remote it from disk
2.4.3. Create custom dialog
click on menu: File -> New
enter file name: mytestdlg
file kind: replace "Blank file" with "Qt3 Dialog (.ui)"
click on OK
click on OK
Be very carefull about the file name!
2.4.4. Generate code for the custom dialog
A dummy code can be easily created by the subclassing wizard:
right click on the mytestdlg.ui file
select: Subclassing Wizard...
enter Class name: MyTest
select all the methods
select: Reformat source
click on OK
click on OK
2.4.5. Change window instantiation
The file main.cpp needs to be modified in order to instantiate the custom dialog instead of the "dummy" main window:
Include the correct header file:
replace line: #include "test.h"
with line : #include "mytest.h"
Use dialog pointer instead of main window pointer in the main() method:
replace: test *mainWin = 0;
with : MyTest* mainWin = 0;
Remove code dedicated to main window behaviour in the main() method:
remove the "if(){...}else{...}" code
and replace it with:
mainWin = new MyTest();
app.setMainWidget(mainWin);
mainWin->show();
2.4.6. Rebuild the project
click on menu: Build -> Run automake & friends
click on menu: Build -> Run configure
click on menu: Build -> Build Project (or press F8)
click on menu: Build -> Execute Program (or press SHIFT + F9)
2.5. References
http://docs.linux.cz/programming/kde/women.kde.org/articles/tutorials/kdevelop3/creating.html
3.1. Quanta
sudo apt-get install quanta
4.1. Author
Emidio Planamente <eplanamente@gmx.ch>
4.2. History
Version 1
First public release
|