You are not logged in.

Barney`

Beginner

  • "Barney`" is male
  • "Barney`" started this thread

Posts: 37

Location: Paris, France

Occupation: Student

  • Send private message

1

Sunday, January 2nd 2005, 4:13pm

Questions from a newbie

I created a main window and a dialog with qt designer, and I want the dialog to be shown/opened when I click on an icon of a ToolBar.
I thought I could do it with the menu Edit>Connections but when I select the main window, all the receivers and senders belong to this windows and not the dialog.

I would also like to know how to generate .cpp .h and .exe files when my .ui and .pro are achieved?

Everytime, each icon, image, pixam, etc... of a file disapear when I load it. I always have to add them each time I open qt designer and I load my file.

I would like to know how to solve those three problems. Thank you very much for your help.

This post has been edited 1 times, last edit by "Barney`" (Jan 2nd 2005, 11:37pm)


eR@$3r

Beginner

  • "eR@$3r" is male

Posts: 4

Location: Thessaloniki @ Greece

Occupation: Student

  • Send private message

2

Sunday, January 2nd 2005, 10:21pm

For the first problem one solution is to create a slot in the MainForm and place the following code :

Source code

1
2
3
4
5
6
void MainForm::actionOpen() {
    MyDialog myDialog(this,"MyDialog",true);
    int rc = myDialog.exec();
    if (rc == QDialog::Rejected) ...
    ...
}


for the third problem use Project > Image Collection... to add your images. If this doesn't work add the code below to your project file :

Source code

1
2
3
4
5
6
IMAGES = images/1.png \
	     images/2.png \
	     images/3.png \
	     images/4.png \
	     5.png \
	     6.png


As for the second problem, I can't understand what you mean. Terminated?

Barney`

Beginner

  • "Barney`" is male
  • "Barney`" started this thread

Posts: 37

Location: Paris, France

Occupation: Student

  • Send private message

3

Sunday, January 2nd 2005, 11:22pm

Ok thanks!:)

I'm sorry if I make mistakes, I'm French. I meant when I've finished to create all the .ui of my project (Is it clear now? :D), what should I do to get an executable file and c++ files?

I tried to use the following sequence of commands :

qmake my_project.pro
(this one works)

make
(an error happens )

Source code

1
2
3
4
/usr/lib/gcc-lib/i586-mandrake-linux-gnu/3.3.2/../../../crt1.o(.text+0x18): In function `_start':
../sysdeps/i386/elf/start.S:98: undefined reference to `main'
collect2: ld returned 1 exit status
make: *** [VIA] Erreur 1


I know why I had the third problem : because I forgot to add the .ui files in my .pro file
By the way, when I load my project, the .ui files linked to it are not loaded at the same time, I've to add them each time to work on it :/ Is there another solution?


Where can I place the code you gave me ? I don't have .cpp files yet and I've found nothing in qtdesigner to add it.

This post has been edited 5 times, last edit by "Barney`" (Jan 2nd 2005, 11:52pm)


jacek

Master

  • "jacek" is male

Posts: 2,729

Location: Warsaw, Poland

  • Send private message

4

Monday, January 3rd 2005, 12:13am

Source code

1
2
3
4
/usr/lib/gcc-lib/i586-mandrake-linux-gnu/3.3.2/../../../crt1.o(.text+0x18): In function `_start':
../sysdeps/i386/elf/start.S:98: undefined reference to `main'
collect2: ld returned 1 exit status
make: *** [VIA] Erreur 1

It seems that you don't have a main function. Qt Designer can generate one for you. If you open your
project in Qt Designer, select File->New, then "C++ Main-File (main.cpp)" and click OK (it will ask
to select main form).

Quoted

Where can I place the code you gave me ? I don't have .cpp files yet and I've found nothing in qtdesigner to add it.

Qt Designer is rather a visual .ui file editor, than IDE. You can add code to your forms using ui.h files,
but since you are using Linux, you could try KDevelop (it can cooperate with Qt Designer).

Barney`

Beginner

  • "Barney`" is male
  • "Barney`" started this thread

Posts: 37

Location: Paris, France

Occupation: Student

  • Send private message

5

Monday, January 3rd 2005, 2:06am

OK!!!!!
I didn't notice that this choice appeared once I loaded my .pro!
Thanks, you saved my life!!!! :D

Is it possible to get .cpp and .h files? I would like to have these file to modify them.

Could you explain me the instructions of the function of the action I created, please? I tried to adapt the code but I didn't succeed. :(

This post has been edited 3 times, last edit by "Barney`" (Jan 3rd 2005, 3:17am)


6

Monday, January 3rd 2005, 4:06am

the files are all in the same folder where ur programs created
I know i'm not as good as you, but I've try too. :(
Gimme more time and I'll be as good as you. ;)

Barney`

Beginner

  • "Barney`" is male
  • "Barney`" started this thread

Posts: 37

Location: Paris, France

Occupation: Student

  • Send private message

7

Monday, January 3rd 2005, 11:13am

I used qmake and make, but I only have :
my_project.pro
main_window.ui
my_dialog1.ui
my_dialog2.ui
Makefile
main.cpp
main_window.ui.h
my_project

I would like to have main_window.cpp, my_dialog1.cpp, etc...

  • "wysota" is male

Posts: 4,276

Location: Warsaw, POLAND

  • Send private message

8

Monday, January 3rd 2005, 11:20am

Quoted

Originally posted by Barney`
I would like to have main_window.cpp, my_dialog1.cpp, etc...


This files will be generated by uic and moc when you run make.

Barney`

Beginner

  • "Barney`" is male
  • "Barney`" started this thread

Posts: 37

Location: Paris, France

Occupation: Student

  • Send private message

9

Monday, January 3rd 2005, 1:58pm

I typed ls -la in my shell instead of ls -l and all the .cpp and .h were in .uic/ folder :]
I always use ls -l but fortunately I tought to use ls -la

PS : I still have the first problem :(

This post has been edited 1 times, last edit by "Barney`" (Jan 3rd 2005, 5:08pm)


eR@$3r

Beginner

  • "eR@$3r" is male

Posts: 4

Location: Thessaloniki @ Greece

Occupation: Student

  • Send private message

10

Monday, January 3rd 2005, 11:38pm

Fisrt we create a MyDialog object. For the parameters read qt assistant. It is a great documentation.
Then we show myDialog by calling exec(). After you close the dialog window, exec() returns a value.
if (rc == QDialog::Rejected) means that you pressed Cancel. Then execute whatever you like.
In file main_window.ui.h create a slot called 'actionOpen' using qtdesigner.
To do that click on main_window, where the project files are, and then Edit > Slots...
Rename 'newSlot()' to 'actionOpen()' and insert this code :

Source code

1
2
3
4
5
6
void main_window::actionOpen() {
    my_dialog1 myDialog(this,"unused_text_i_think_just_fill_something",true);
    int rc = myDialog.exec();
    if (rc == QDialog::Rejected) ...
    ...
}


As for the files not being loaded here is a sample of a project file :

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
unix {
  UI_DIR = .ui
  MOC_DIR = .moc
  OBJECTS_DIR = .obj
}

TEMPLATE    = app
LANGUAGE    = C++

CONFIG    += qt warn_on release

HEADERS    += notes.h
SOURCES    += main.cpp
FORMS    = Form1.ui \
          Form2.ui \
          MainForm.ui
IMAGES = images/1.png \
         images/2.png \
         images/3.png


You can change the project file using a text editor.
UI_DIR holds .h and .cpp files.
MOC_DIR holds moc_*.cpp files.
OBJECTS_DIR holds .o files.
HEADERS holds the .h you use in qtdesigner.
SOURCES holds the .cpp files you use in qtdesigner (usually the file main.cpp).
FORMS holds the .ui files you use in qtdesigner.
IMAGES holds the image collection.

As wysota said, when you run make, uic and moc create the files you want.
uic reads .ui files and genetares .h and .cpp files.
moc reads the generated .h files and then generates moc_*.cpp files.
Finally you get the .o files and the executable of course.
In a generated .cpp there is the corresponding include for .ui.h.
I mean in form1.cpp there is a '#include "form1.ui.h"'.
You can change the generated .h and .cpp files but then you will work with form1.ui.h, form1.h and form1.cpp.
After making changes, keep in mind that you should not use the generated makefile because all your changes in .h and .cpp files will be lost.
Compile the files on your own every time or change the makefile...

Personally I use only qtdesigner. I create the forms, add code to .ui.h and run qmake and make. It is possible to use c/c++ code within qtdesigner. Such as functions from stdlib.h e.t.c.

Barney`

Beginner

  • "Barney`" is male
  • "Barney`" started this thread

Posts: 37

Location: Paris, France

Occupation: Student

  • Send private message

11

Tuesday, January 4th 2005, 1:27pm

I have thoses following errors for the compilation :

Source code

1
2
3
4
5
6
7
/home/donkey/tmp/cctV9vUt.o(.text+0x7b): In function `VIA::Preferences_activated()':
: undefined reference to `PreferencesWindow::PreferencesWindow[in-charge](QWidget*, char const*, bool, unsigned)'
/home/donkey/tmp/cctV9vUt.o(.text+0xad): In function `VIA::Preferences_activated()':
: undefined reference to `PreferencesWindow::~PreferencesWindow [in-charge]()'
/home/donkey/tmp/cctV9vUt.o(.text+0xd3): In function `VIA::Preferences_activated()':
: undefined reference to `PreferencesWindow::~PreferencesWindow [in-charge]()'
collect2: ld returned 1 exit status


" Then execute whatever you like."
For instance?

This post has been edited 1 times, last edit by "Barney`" (Jan 4th 2005, 1:32pm)


djanubis

Professional

  • "djanubis" is male

Posts: 1,370

Location: Moulins France

Occupation: Software ingeneering

  • Send private message

12

Tuesday, January 4th 2005, 2:58pm

Could mean the file where you have your preferencesWindow class implemented is not in the file list for the project or (if it is in a lib) you don't have a link reference to the lib.
Never patch not working code. Rewrite it !
Never patch badly designed classes. Recreate them cleanly.
(Excerpts from Computing Bible)

Home of the Lab project

eR@$3r

Beginner

  • "eR@$3r" is male

Posts: 4

Location: Thessaloniki @ Greece

Occupation: Student

  • Send private message

13

Tuesday, January 4th 2005, 8:16pm

I agree with djanubis.
Why don't you attach the code ?
It would be helpful..

Example :

Source code

1
2
3
4
5
6
7
8
9
10
void main_window::actionOpen() {
    my_dialog1 myDialog(this,"unused_text_i_think_just_fill_something",true);
    int rc = myDialog.exec();
    if (rc == QDialog::Rejected) {
        QMessageBox::information(this,"Cancel pressed.","My App",QMessageBox::Ok);
    }
    else {
        QMessageBox::information(this,"OK pressed.","My App",QMessageBox::Ok);
    }
}
Got an error msg ? Get the src and fix it.
It's an OS bug ? Get the kernel src and fix it.
It's a h/w malfunction ? Get a new pc.
If you see the msg again, replace user and press any key to continue... :D

Barney`

Beginner

  • "Barney`" is male
  • "Barney`" started this thread

Posts: 37

Location: Paris, France

Occupation: Student

  • Send private message

14

Thursday, January 6th 2005, 1:34am

How to delete this post please?

This post has been edited 3 times, last edit by "Barney`" (Jan 6th 2005, 2:18am)