PDA

View Full Version : Problem displaying my main window



Salazaar
12th May 2007, 20:33
Hi. I've got a question. I have created my main window using designer and translated it into Qt code. So after translations I received a ui_Maker.h file:

http://www.insidetennis.yoyo.pl/ntd.txt

And how can I display this main window (called MainWindow) ?
I tried this in main.cpp:

#include "ui_Maker.h"

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainWindow->show();
return app.exec();
}
but there appear error that MainWindow is undeclared. What did I do wrong? And how can I correct it? Btw. my test.pro file:

CONFIG += qt
HEADERS += ui_Maker.h
SOURCES += main.cpp

Regards

jpn
12th May 2007, 20:43
Please read Using a Component in Your Application (http://doc.trolltech.com/4.2/designer-using-a-component.html). Pay attention to single and multiple inheritance approaches. The direct approach is pretty inflexible and not suggested.

Salazaar
12th May 2007, 21:22
And what should I type:

#include "ui_Maker.h"

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QDialog *window = new QDialog;
Ui::ImageDialog ui; // what should I type here, because ImageDialog is an example??
ui.setupUi(MainWindow); // here I renamed window to MainWindow

MainWindow->show(); // here I renamed window to MainWindow
return app.exec();
}
And is anything correct in this main.cpp? Regards

jpn
12th May 2007, 21:30
This is the "direct approach" which was suggested against using. But oh well, here goes:


#include "ui_Maker.h"

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QMainWindow *window = new QMainWindow; // create a main window, that's what you have designed
Ui::MainWindow ui;
ui.setupUi(window);
window->show();
return app.exec();
}


PS. Please use the "#"-button for highlighting code blocks.

Salazaar
12th May 2007, 21:56
Ok, so I have done it, but in compiling it, there appear error:

collect2: ld returned 1 exit status
make[1]: *** [release\Test.exe] Error 1
make[1]: Leaving directory `C:/Qt/4.2.3/Qt'
make: *** [release] Error 2

What is wrong?
Regards

jpn
12th May 2007, 21:58
What does the .pro file look like? What's the first error?

Salazaar
12th May 2007, 22:52
This is the .pro file


CONFIG += qt
HEADERS += ui_Maker.h
SOURCES += main.cpp
And this is what appear in console. There are really many errors such as:
in main.cpp - undefined reference to...
and the first error is [release\test.exe] error 1
and second is
[release] error 2

So what's wrong?
Kind regards

jpn
12th May 2007, 23:17
This is the .pro file


CONFIG += qt
HEADERS += ui_Maker.h
SOURCES += main.cpp

Please follow the directions (http://doc.trolltech.com/4.2/designer-using-a-component.html) I already gave you once. There is no need to generate the header and include it to the project by hand. You should be using a variable FORMS instead.

Edit: Clean up the folder. Leave only files main.cpp and Maker.ui. Run "qmake -project" and you'll get a proper project file.



And this is what appear in console. There are really many errors such as:
in main.cpp - undefined reference to...
and the first error is [release\test.exe] error 1
and second is
[release] error 2
Well, you managed to cut the interesting part off. :) "error 1" or "error 2" does not tell anything valuable. Please paste all the errors including the undefined reference.

wysota
12th May 2007, 23:40
Maybe he should paste only the first few? ;)

And remember about closing the memory leak when you come to this point :)

jpn
12th May 2007, 23:47
Maybe he should paste only the first few? ;)
That's what I asked in the first place but it didn't work so I tried another approach.. ;)


And remember about closing the memory leak when you come to this point :)
First of all, I tried to advise against using the direct approach. Anyway, the same leak is also in the example (http://doc.trolltech.com/4.2/designer-using-a-component.html#the-direct-approach)..

Salazaar
13th May 2007, 10:18
Please follow the directions (http://doc.trolltech.com/4.2/designer-using-a-component.html) I already gave you once. There is no need to generate the header and include it to the project by hand. You should be using a variable FORMS instead.

But if I want to make changes in the maker file, which I can't do in Designer such as connecting tools->sort to another dialog, I have to generate header file and make changes and add it to project by hand. Is that right?
EDIT:
I have generated project file by makefile but there appear the same errors such as:
in main.cpp - undefined reference to _imp__ZN7QString4freeEPNS
What is wrong?
EDIT:
I think this is problem with my Qt installation, because when I try to compile simple application lioke this:

#include <QApplication>
#include <QPushButton>

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

QPushButton hello("Hello world!");
hello.resize(100, 30);

hello.show();
return app.exec();
}
There appear errors such as undefined reference to QApplication, QPushButton and the same as in compiling converted ui file
So, I'll ask once again. What's wrong? I have installed Qt to my mingw compiler, set 3 environment variables. I have done it with Marcel's help, so everything should be set.....
Regards
EDIT:
Oh, now everything's ok, I just forgot to include QApplication to main file:D

jpn
13th May 2007, 12:31
But if I want to make changes in the maker file, which I can't do in Designer such as connecting tools->sort to another dialog, I have to generate header file and make changes and add it to project by hand. Is that right?
As the generated header says in the header comment, do never edit them by hand. Your changes will be lost if you ever want do adjust the designed form and the header is generated again. Use either single inheritance (http://doc.trolltech.com/4.2/designer-using-a-component.html#the-single-inheritance-approach) or multiple inheritance (http://doc.trolltech.com/4.2/designer-using-a-component.html#the-multiple-inheritance-approach) approach and do the changes in the actual widget/dialog/window class (which loads the designed form).

Salazaar
13th May 2007, 13:35
I really don't understand what is described in this link.

wysota
13th May 2007, 14:40
Please use the "code" tag (# button) instead of "qtclass" (Qt button) when pasting code.

Salazaar
13th May 2007, 16:33
So how can I connect other dialogs to my main windows action (it is all done with Qt Designer)

jpn
13th May 2007, 16:37
Hopefully this helps:
FAQ: I have two forms. How to open a second form after a button is clicked in the first one? (http://www.qtcentre.org/forum/faq.php?faq=qt_general_category#faq_qt_designer_2f orms)

Salazaar
13th May 2007, 17:40
Ok, thanks, I'll try it. But if I want to make things, which I can't do in Designer, so how can I make these changes without changing code?

wysota
13th May 2007, 17:59
Look again at the links JP gave you in post #12.

Salazaar
13th May 2007, 18:27
Hi. I tried to do what's described in http://www.qtcentre.org/forum/faq.php?faq=qt_general_category#faq_qt_designer_2f orms
but I don't know how to do it. I'd be veery thankful if somebody will do it on my code and add comments in the parts of code which were changed:

Dialog file which I want to connect to actionAbout http://www.insidetennis.yoyo.pl/ui_About.txt

And my main window
http://www.insidetennis.yoyo.pl/ui_MainWindow.txt (Attention! The file is called ui_maker.h, not ui_mainwindow.h !!!)

if someone can do it, I'd be very thankful...

jpn
13th May 2007, 18:38
Please, consider going through the nice tutorials shipped with Qt, starting from Qt Tutorial 1 - Hello World (http://doc.trolltech.com/4.2/tutorial-t1.html). We are not here to teach you the basics but to help you with problems you may encounter. ;)

Salazaar
13th May 2007, 18:45
I have C++ GUI Programming with Qt 4 book. And I know something already, but I can't do anything about that, so I will ask you once more, to correct my code ;)

Salazaar
13th May 2007, 19:51
I added this:

void Ui_MainWindow::openUi_Dialog(){
static Ui_Dialog *Ui_Dialog = new Ui_Dialog(this);
Ui_Dialog->show();
Ui_Dialog->activateWindow(); // or form2->setActiveWindow() in Qt3
Ui_Dialog->raise();
}
into Ui_MainWindow class. Is that correctly?
EDIT:
No, it isn't. When I do it I have errors that MainWindow class does not have a member called raise, acitvateWindow and show. Even if I paste it out of this class there are errors:
class Ui-Dialog has no member called raise, show and activateWindow. So how should I do it?

wysota
13th May 2007, 20:20
Again with big red characters:

Don't change the code of the class generated by UIC. Subclass along the proper widget class and put additional code there.

There... I hope that makes it clear ;) Oh... and I'm sure it's well explained in the book you mentioned.

Salazaar
13th May 2007, 20:26
Ok, I won't change the code, so how can I connect dialog to actionAbout slot? I'd be satisfied with a code. ;)
Regards
-------------------
Widzę, że nie jestem sam na tym forum ;)

wysota
13th May 2007, 21:00
You don't have a dialog. You only have an UI definition. You have to use the definition on a dialog and not on its own. You're asking for code and we're constantly redirecting you to an article that contains the code you ask for. Furthermore GUI Programming with Qt4 book also contains the code you ask for. Please read and follow "The Single Inheritance Approach" section from the docs.

Salazaar
14th May 2007, 07:23
Right. Than, I have a question concerning code that jpn gave me:

#include "ui_Maker.h"



int main(int argc, char *argv[])

{

QApplication app(argc, argv);

QMainWindow *window = new QMainWindow; // create a main window, that's what you have designed

Ui::MainWindow ui;

ui.setupUi(window);

window->show();

return app.exec();

}
Why it's
Ui::MainWindow ui ? I didn't find anything what should be called by this.

jpn
14th May 2007, 07:59
Why it's
Ui::MainWindow ui ? I didn't find anything what should be called by this.
The name was picked from Marker.ui pasted in the very first post of yours. However, it was only an attempt to get you going. You really should forget about the direct approach and use better alternates.

Salazaar
14th May 2007, 08:30
Like The Single Inheritance Approach and The Multiple Inheritance Approach ... Ok, I'm working at it... and this MainWindow is the name of my main window which I gave to it by designer, right?

jpn
14th May 2007, 08:35
and this MainWindow is the name of my main window which I gave to it by designer, right?
That's right.

patrik08
14th May 2007, 08:48
I use a tool to create cpp (source) && h (header file)


Finaly on main to show the gui you use on main...
## MainWindow is class name....
MainWindow::self()->setWindowTitle( _PROGRAM_TITLE_ );
MainWindow::self()->show();


download QTutils tool -> http://ppk.ciz.ch/qt_c++/QT_utils.zip
cd QT_utils
qmake
make

Open QTUtils insert the class name on top && select mainwindow/Dialog/Widged type same as ui file && generate the code as header & source ... or only as header....

Put the file on projekt dir && run && main.cpp
on cmd dir qmake -project
call the dialog on main...

but on top from pro file ...

MOC_DIR = build/.moc
RCC_DIR = build/.rcc
OBJECTS_DIR = build/.obj
UI_DIR = ui

and final
qmake && make.

Salazaar
14th May 2007, 08:55
But Direct Approach shows how to show the dialog, not to make changes in it. And to not to make a new thread, I'll ask here, can I create slots in designer? And in this code, which is here: http://doc.trolltech.com/4.2/designer-using-a-component.html#the-single-inheritance-approach
I have to paste into main.cpp file, right?
Edit:
Patrik, there's no problem with creating main file, but with connecting mainwindow to other applications and with creating slots

jpn
14th May 2007, 09:36
But Direct Approach shows how to show the dialog, not to make changes in it. And to not to make a new thread, I'll ask here, can I create slots in designer?
No, you can't create slots in Designer.



And in this code, which is here: http://doc.trolltech.com/4.2/designer-using-a-component.html#the-single-inheritance-approach
I have to paste into main.cpp file, right?
Look at the Calculator Form Example (http://doc.trolltech.com/4.2/designer-calculatorform.html). It uses the single inheritance approach and custom slots.

wysota
14th May 2007, 10:00
And to not to make a new thread, I'll ask here, can I create slots in designer?

http://www.qtcentre.org/forum/faq.php?faq=qt_designer_category

Salazaar
14th May 2007, 18:47
No, you can't create slots in Designer.


Look at the Calculator Form Example (http://doc.trolltech.com/4.2/designer-calculatorform.html).But in http://doc.trolltech.com/4.2/designer-using-a-component.html#the-multiple-inheritance-approach it shows how to add a custom slot, but it doesn't show how to connect action to another dialog

wysota
14th May 2007, 19:09
Please connect all the knowledge gathered in this thread and use it together. If you have any doubt, consult the FAQ and the article you were given. If you still have problems, ask *specific* questions.

Salazaar
14th May 2007, 20:14
Hi. So, I've got a question. There appear errors:

In member function void MainWindow::cbazion()
expected primary-expression before ) token
expected ; before) token
expected } at end of input

And this is this file:

#include <QtGui>

#include "maker.h"

MainWindow::MainWindow(QMainWindow *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
}

void MainWindow::abcziom()
{

}

void MainWindow::cbaziom()
{

)

jacek
14th May 2007, 20:40
Could you post the contents of maker.h file?

wysota
14th May 2007, 21:39
You have a right bracket instead of a right brace in the last line.

Salazaar
16th May 2007, 19:52
This is the full maker.h content:

#ifndef MAKER_H
#define MAKER_H

#include "ui_maker.h"

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
MainWindow(QMainWindow *parent = 0);

private slots:
void abcziom();
void cbaziom();

private:
Ui::MainWindow ui;
};

#endif

So, what's wrong?

wysota
16th May 2007, 20:10
As I said, you have a wrong character in your implementation file.

Salazaar
16th May 2007, 20:30
Ok, it works properly. And how can I connect other dialog to one of actions defined in ui_maker.h?? Because I can't understand multiple inheritance

jacek
16th May 2007, 21:28
And how can I connect other dialog to one of actions defined in ui_maker.h??
For example you can use the automatic connections mechanism, by adding a specially named slot to your class:
void MainWindow::on_someAction_triggered()
{
OtherDialog dlg( this );
dlg.exec();
}
Where someAction is the name of the action you want to connect to and triggered() is the signal you want to react on.


Because I can't understand multiple inheritance
It looks like you have taken the single inheritance approach, so you don't use the multiple inheritance anywhere.

Salazaar
17th May 2007, 15:33
Ok, so I create slot:


void MainWindow::on_actionAbout_triggered()

{

OtherDialog dlg( this );

dlg.exec();

}
And, what's the next step?

wysota
17th May 2007, 15:35
Can't you just follow a tutorial or something? It'll be way faster if you do...

Salazaar
17th May 2007, 16:07
Because I can't understand multiple inheritance
So I'd like you to show me how to do it, please.Regarsds

jacek
17th May 2007, 16:59
And, what's the next step?
Compilation ;)

Qt will handle the rest, provided that you have that OtherDialog class. How does your main() function look like?

wysota
17th May 2007, 16:59
What does multiple inheritance have to do with the code you pasted above?

Here is a list of different examples and tutorials which you might want to take a look at:
http://doc.trolltech.com/4.2/examples.html

Here is an article stating step by step how to use forms created in Designer:
http://doc.trolltech.com/4.2/designer-using-a-component.html

Here is a link to The Independent Qt Tutorial by Johan Thelin which is a tutorial on Qt3 for beginners. If you have trouble handling Qt basics, it'll be fine for you even if you use Qt4:
http://www.digitalfanatics.org/projects/qt_tutorial/

The problem is that you're asking questions without telling us what you want. In particular I have no idea what "next step" you were referring to in your previous post. We don't know what you already did, what you're planning to do, etc.

wysota
17th May 2007, 17:01
Qt will handle the rest, provided that you have that OtherDialog class.

You're assuming he has a actionAbout action in his class :)

Salazaar
17th May 2007, 20:27
Compilation ;)

Qt will handle the rest, provided that you have that OtherDialog class
I don't understand. The only thing that I have to do is defining this? But what should be in OtherDialog and dlg places in my case, if I have a Main Window called MainWindow and all actions defined in ui_maker.h file? This file is designed by designer. And I have to include this ui_Dialog file, yes? Regards

Salazaar
17th May 2007, 20:29
Compilation ;)

Qt will handle the rest, provided that you have that OtherDialog class
I don't understand. The only thing that I have to do is defining this? But what should be in OtherDialog and dlg places in my case, if I have a Main Window called MainWindow and a dialog called Dialog? All actions aredefined in ui_maker.h file, this file is designed by designer. I have this two files: maker.h:

#ifndef MAKER_H
#define MAKER_H

#include "ui_maker.h"

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
MainWindow(QMainWindow *parent = 0);

private slots:
void abcziom();
void cbaziom();

private:
Ui::MainWindow ui;
};

#endif

and ui_about:

#ifndef UI_ABOUT_H
#define UI_ABOUT_H

#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QDialog>
#include <QtGui/QLabel>
#include <QtGui/QPushButton>

class Ui_Dialog
{
public:
QLabel *label;
QLabel *label_2;
QLabel *label_3;
QPushButton *pushButton;

void setupUi(QDialog *Dialog)
{
Dialog->setObjectName(QString::fromUtf8("Dialog"));
label = new QLabel(Dialog);
label->setObjectName(QString::fromUtf8("label"));
label->setGeometry(QRect(15, 23, 361, 16));
label->setLayoutDirection(Qt::LeftToRight);
label->setTextFormat(Qt::AutoText);
label_2 = new QLabel(Dialog);
label_2->setObjectName(QString::fromUtf8("label_2"));
label_2->setGeometry(QRect(15, 50, 351, 81));
label_2->setLineWidth(1);
label_2->setMidLineWidth(0);
label_2->setTextFormat(Qt::RichText);
label_2->setAlignment(Qt::AlignLeading|Qt::AlignLeft|Qt::Al ignTop);
label_2->setWordWrap(true);
label_3 = new QLabel(Dialog);
label_3->setObjectName(QString::fromUtf8("label_3"));
label_3->setGeometry(QRect(25, 163, 171, 21));
pushButton = new QPushButton(Dialog);
pushButton->setObjectName(QString::fromUtf8("pushButton"));
pushButton->setGeometry(QRect(260, 250, 75, 23));
pushButton->setDefault(true);
pushButton->setFlat(false);

retranslateUi(Dialog);

QSize size(400, 293);
size = size.expandedTo(Dialog->minimumSizeHint());
Dialog->resize(size);

QObject::connect(pushButton, SIGNAL(clicked()), Dialog, SLOT(close()));

QMetaObject::connectSlotsByName(Dialog);
} // setupUi

void retranslateUi(QDialog *Dialog)
{
Dialog->setWindowTitle(QApplication::translate("Dialog", "About", 0, QApplication::UnicodeUTF8));
Dialog->setAccessibleName(QApplication::translate("Dialog", "About", 0, QApplication::UnicodeUTF8));
label->setText(QApplication::translate("Dialog", "About TimeTable Maker", 0, QApplication::UnicodeUTF8));
label_2->setText(QApplication::translate("Dialog", "...", 0, QApplication::UnicodeUTF8));
label_3->setText(QApplication::translate("Dialog", "Thank you for using TimeTable Maker", 0, QApplication::UnicodeUTF8));
pushButton->setText(QApplication::translate("Dialog", "OK", 0, QApplication::UnicodeUTF8));
Q_UNUSED(Dialog);
} // retranslateUi

};

namespace Ui {
class Dialog: public Ui_Dialog {};
} // namespace Ui

#endif // UI_ABOUT_H

wysota
17th May 2007, 20:40
I think you mentioned you have the book "GUI Programming with Qt4". Did you read the second chapter? Especially sections "Subclassing QDialog" and "Rapid Dialog Design"? These explain how to do what you're trying to do.

Salazaar
17th May 2007, 20:42
No, but I'll read it ;) Ok, so I will look at it

wysota
17th May 2007, 20:46
Don't have a look. Read it.

Salazaar
17th May 2007, 20:47
And after it I will know how to do it...I would like to know ;)

wysota
17th May 2007, 20:50
Yes. You're asking about very simple things and it seems that you even didn't look at the documentation or the book. We won't teach you C++ here. If you have trouble with C++ I suggest you also take a look at our links section and download (and read, at least parts of it) "Thinking in C++".

Salazaar
17th May 2007, 21:09
I'd like the Chapter 2 to be simplier than designer using a component? ;) But there isn't much to do with the code in post #50, right?

wysota
17th May 2007, 21:42
Read and understand the chapter. We can give you the exact code for your problem but then you won't learn anything and you'll come right back with a simmilar issue.

Salazaar
18th May 2007, 15:58
But in book, there appear one more line after QApplication app... It's

Ui::MainWindow ui
which not appear in my application, but it works.

Salazaar
18th May 2007, 16:37
Hi than. I read chapter 2, I understand it, but I still don't know how to connect action to another dialog. It shows how to make slots and use it, but not how to connect two different dialogs. Regards

jacek
18th May 2007, 17:53
but not how to connect two different dialogs.
What do you mean by "connect two different dialogs"? Do you want to connect a signal from one dialog to a slot in the other one?

Salazaar
18th May 2007, 19:46
I want to connect action in my menu called actionAbout to dialog which is in ui_about

jacek
18th May 2007, 20:07
I want to connect action in my menu called actionAbout to dialog which is in ui_about
Define "connect". What exactly you want to happen?

Salazaar
18th May 2007, 20:22
if a ucer clicks a button, than about dialog is displayed

jacek
18th May 2007, 20:34
if a ucer clicks a button, than about dialog is displayed
I've already shown you how to do it.

Have you read the third chapter?

Salazaar
18th May 2007, 21:09
Right


void MainWindow::on_actionAbout_triggered()

{

OtherDialog dlg( this );

dlg.exec();

}
And if I have a dialog included to my file called Dialog, so the OtherDialog will the replaced by Dialog? And what about "dlg"? and must on_aboutAction_triggered() be defined in slots section? I mean the same way that I do it with other functions?

jacek
18th May 2007, 22:33
And if I have a dialog included to my file called Dialog, so the OtherDialog will the replaced by Dialog?
Yes, you have to replace it with the name of a class you want to use.


And what about "dlg"?
It doesn't matter, it's just a variable.


and must on_aboutAction_triggered() be defined in slots section?
Yes, it has to be a slot.

As a homework, please, get a copy of C++ Primer (Polish edition is called Podstawy języka C++) by S. Lippman and J. Lajoie and read parts 2--5.

Salazaar
19th May 2007, 23:23
;) And to connect dialog to a slot, I have to do this, what is described in posts #65, 66
and also include this ui_about.h dialog file and nothing else? Will it be done correctly?

wysota
20th May 2007, 09:02
You don't connect a dialog to a slot. You connect a signal triggered() of the action actionAbout to a slot that has code which creates the dialog object and calls exec() on it to show it as modal.

Salazaar
20th May 2007, 18:02
Your absolutely right.

Salazaar
20th May 2007, 18:57
There's a problem. I have those files:
Maker.cpp

#include <QtGui>

#include "maker.h"

MainWindow::MainWindow(QMainWindow *parent)
: QMainWindow(parent)
{
ui.setupUi(this);

}

void MainWindow::on_actionAbout_triggered()
{


Dialog dlg( this );



dlg.exec();



}

Maker.h

#ifndef MAKER_H
#define MAKER_H

#include "ui_maker.h"
#include "ui_about.h"


class MainWindow : public QMainWindow, public Ui::MainWindow
{
Q_OBJECT

public:
MainWindow(QMainWindow *parent = 0);

private slots:

void on_actionAbout_triggered();

private:

Ui::MainWindow ui;
};

#endif


ui_about.h


#ifndef UI_ABOUT_H
#define UI_ABOUT_H

#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QDialog>
#include <QtGui/QLabel>
#include <QtGui/QPushButton>

class Ui_Dialog
{
public:
QLabel *label;
QLabel *label_2;
QLabel *label_3;
QPushButton *pushButton;

void setupUi(QDialog *Dialog)
{
Dialog->setObjectName(QString::fromUtf8("Dialog"));
label = new QLabel(Dialog);
label->setObjectName(QString::fromUtf8("label"));
label->setGeometry(QRect(15, 23, 361, 16));
label->setLayoutDirection(Qt::LeftToRight);
label->setTextFormat(Qt::AutoText);
label_2 = new QLabel(Dialog);
label_2->setObjectName(QString::fromUtf8("label_2"));
label_2->setGeometry(QRect(15, 50, 351, 81));
label_2->setLineWidth(1);
label_2->setMidLineWidth(0);
label_2->setTextFormat(Qt::RichText);
label_2->setAlignment(Qt::AlignLeading|Qt::AlignLeft|Qt::Al ignTop);
label_2->setWordWrap(true);
label_3 = new QLabel(Dialog);
label_3->setObjectName(QString::fromUtf8("label_3"));
label_3->setGeometry(QRect(25, 163, 171, 21));
pushButton = new QPushButton(Dialog);
pushButton->setObjectName(QString::fromUtf8("pushButton"));
pushButton->setGeometry(QRect(260, 250, 75, 23));
pushButton->setDefault(true);
pushButton->setFlat(false);

retranslateUi(Dialog);

QSize size(400, 293);
size = size.expandedTo(Dialog->minimumSizeHint());
Dialog->resize(size);

QObject::connect(pushButton, SIGNAL(clicked()), Dialog, SLOT(close()));

QMetaObject::connectSlotsByName(Dialog);
} // setupUi

void retranslateUi(QDialog *Dialog)
{
Dialog->setWindowTitle(QApplication::translate("Dialog", "About", 0, QApplication::UnicodeUTF8));
Dialog->setAccessibleName(QApplication::translate("Dialog", "About", 0, QApplication::UnicodeUTF8));
label->setText(QApplication::translate("Dialog", "About TimeTable Maker", 0, QApplication::UnicodeUTF8));
label_2->setText(QApplication::translate("Dialog", "...", 0, QApplication::UnicodeUTF8));
label_3->setText(QApplication::translate("Dialog", "Thank you for using TimeTable Maker", 0, QApplication::UnicodeUTF8));
pushButton->setText(QApplication::translate("Dialog", "OK", 0, QApplication::UnicodeUTF8));
Q_UNUSED(Dialog);
} // retranslateUi

};

namespace Ui {
class Dialog: public Ui_Dialog {};
} // namespace Ui

#endif // UI_ABOUT_H

And if I try to compile it, there appear errors:
maker.cpp - in member function 'void MainWindow:: on_actionAbout_triggered()':
maker.cpp:line 16: Dialog undeclared (first use)
maker.cpp:line 16: Each undeclared identifier is reported only once for each function it appears in
maker.cpp:line 16: Expected ; before 'dlg'
maker.cpp:line 20: 'dlg' undeclared (first use)

What's wrong? I've done everything how you'd described!:(

wysota
20th May 2007, 19:45
Do you have a class called "OtherDialog"?

Salazaar
20th May 2007, 20:01
Do you have a class called "OtherDialog"?
No, I don't have a class called OtherDialog and also don't have class called Dialog (btw. my dialog is called Dialog) How (and where) do I have to create this class? Look at the code I'd posted above. Regards

wysota
20th May 2007, 21:08
So if you don't have such classes, why are you using them? You have to create a subclass of QDialog that uses your uic generated code to initialise itself which is explained in the link you're constantly being pointed to.

Please, understand, there is nothing magical going on here. If you don't implement a class, you can't use it - it won't be created out of thin air. I asked you about your C++ knowledge and I was given an empty answer, but from what I see you don't know much about it. So I repeat Jacek's suggestion to take a good book about C++, be it either C++ Primer, Thinking in C++ (available online) or even Symfonia C++.

The problem here is that if we don't give you exact code you are to copy and paste into your files, there is no way you're going to obtain the result you want, because you don't seem to try to do anything by yourself. It seems that you know what to do, because you implemented the exact same thing that is required here with the main window. I just can't seem to understand why don't you repeat the exact same approach with the dialog.
We're all trying to teach you something here, but it seems we're doing something wrong, so please explain us what exactly you don't know how to do and I'm speaking of some fundamental things - like subclassing, creating variables, single or multiple inheritance, etc. Is this all known to you? Do you have any trouble handling those basics?

Salazaar
21st May 2007, 07:03
Do you have any trouble handling those basics?
A bit. Do I have to subclass this Dialog in the same way I was subclassing MainWindow?

wysota
21st May 2007, 07:59
A bit.
Great, now we're getting somewhere. Please, if at any time you don't understand what we say (any term, code, etc.) just say so and we'll explain it.


Do I have to subclass this Dialog in the same way I was subclassing MainWindow?

Yes. This is exactly the same situation - you have a UI definition in one class and you want to apply it to a widget class (like QDialog or QMainWindow).

Salazaar
21st May 2007, 08:35
Great, now we're getting somewhere. Please, if at any time you don't understand what we say (any term, code, etc.) just say so and we'll explain it.
Thanks;)

And can I subclass dialog in the same file I was subclassing MainWindow (maker.h, and include ui_about.h, ui_maker.h) ?

wysota
21st May 2007, 09:14
Yes, but I suggest you use separate pair of files for that. You'll get cleaner code and faster compilation.

Salazaar
22nd May 2007, 14:58
But in this case (subclassing QDialog) I don't define slots, do I?

wysota
22nd May 2007, 15:36
Do you need any?

Salazaar
22nd May 2007, 15:40
I suppouse no, because I'd defined all importand slots when I was subclassing MainWindow

wysota
22nd May 2007, 20:32
So the answer is no, you don't define slots :)

Salazaar
23rd May 2007, 10:18
Thanks:) And I've got one more question, why some slots are defined in private slots and some are defined in private? Both are private sections of MainWindow class, what's the difference?

jpn
23rd May 2007, 15:49
C++ access qualifiers public, protected and private (refer to you favourite C++ book for more explanation) apply to slots as well.

A slot is not a C++ but a Qt term. A normal C++ function is not a slot but a slot is a function. That is, a normal C++ function cannot be used as a slot in a connect statement but a slot can be called like a normal C++ function. A function needs to be explicitly declared as a slot to be able to use it as a slot. So there are no "slots defined in private slots" and "slots defined in private". Only the former are slots.

Salazaar
24th May 2007, 15:59
So we define slots in private slots, and standard cpp functioms in private, right?

wysota
24th May 2007, 16:40
Yes, that's right.

Salazaar
1st June 2007, 19:27
And in maker.cpp I have to do the same what I was doing with MainWindow:

MainWindow::MainWindow(QMainWindow *parent)
: QMainWindow(parent)
{
ui.setupUi(this);

}

void MainWindow::on_actionAbout_triggered()
{


Dialog dlg( this );



dlg.exec();



}

but without implementing slots, right?

Salazaar
1st June 2007, 19:43
I have a problem. I've implemented this:
Maker.h

#ifndef MAKER_H
#define MAKER_H

#include "ui_maker.h"



class MainWindow : public QMainWindow, public Ui::MainWindow
{
Q_OBJECT

public:
MainWindow(QMainWindow *parent = 0);

private slots:

void on_actionAbout_triggered();

private:

Ui::MainWindow ui;
};

#endif



About.h

#ifndef ABOUT_H
#define ABOUT_H

#include "ui_about.h"



class Dialog : public QDialog, public Ui::Dialog
{
Q_OBJECT

public:
Dialog(QDialog *parent = 0);


private:

Ui::Dialog ui;
};

#endif



Maker.cpp

#include <QtGui>

#include "maker.h"
#include "about.h"

MainWindow::MainWindow(QMainWindow *parent)
: QMainWindow(parent)
{
ui.setupUi(this);

}

void MainWindow::on_actionAbout_triggered()
{


Dialog dlg( this );



dlg.exec();



}




Dialog::Dialog(QDialog *parent)
: QDialog(parent)
{
ui.setupUi(this);

}





And also main.cpp, which contents I won't post, because it's obvious. And there appear errors:
maker.cpp:in member function 'void MainWindow::on_actionAbout_triggered()':
maker.cpp:17:error: no matching function for call to 'Dialog::Dialog(MainWindow* const)
about.h:9:note: candidates are Dialog::Dialog(const Dialog&)
about.h:13:note: Dialog::Dialog(QDialog*)

What's wrong? I thought I'd done everything as it was described in C++ GUI and in this topic. Regards
p.s.
Forum mechanism replaced : D with a smile and also : o with the other smile, as you seen so far

jpn
1st June 2007, 19:47
What's wrong? I thought I'd done everything as it was described in C++ GUI and in this topic.
It should be:


class Dialog ...
{
...
Dialog(QWidget *parent = 0); // notice the type of the parent
...
};

The dialog of yours demands a QDialog as a parent. QMainWindow is not a QDialog but both are QWidgets.

Salazaar
1st June 2007, 20:06
I replaced QDialog with QWidget but it didn't solve the problem:

maker.cpp:31:error: Prototype for Dialog::Dialog(QDialog*) does not match any in class Dialog
about.h:9:error: candidates are Dialog:Dialog(const Dialog&)
about:.h:13:error Dialog::Dialog(QWidget*)

What's wrong now? Regards

jpn
1st June 2007, 20:38
Most likely you forgot to change it in the .cpp file too.

Salazaar
1st June 2007, 20:48
Yes, now I changed it into cpp file too, but there appear error:
maker.cpp: In constructor Dialog::Dialog(QWidget*)
maker.cpp:31:error: Type 'class QWidget' is not a direct base of Dialog

What's wrong, now? Regards,

jpn
2nd June 2007, 05:50
Edit: No, wait. I don't want to spoon-feed the solution.

A parent and a base class are different things. You changed the parent correctly, but you are now calling a wrong base class. Just think of it yourself. ;)

wysota
2nd June 2007, 09:15
p.s.
Forum mechanism replaced : D with a smile and also : o with the other smile, as you seen so far

You can use code or qtclass tags or check the "Disable smilies in text" tick to overcome that.

Salazaar
2nd June 2007, 12:32
Edit: No, wait. I don't want to spoon-feed the solution.

A parent and a base class are different things. You changed the parent correctly, but you are now calling a wrong base class. Just think of it yourself. ;)

So, leave QWidget as I changed it after your advice? I thought about calling wrong base class, but I didn't find the problem. Regards

Salazaar
2nd June 2007, 12:41
I forgot to change one of QDialog to QWidget, but there still are problems;
here is original log of compilation:
http://allyoucanupload.webshots.com/v/2003170322826506289

Salazaar
2nd June 2007, 19:21
Do you know why it doesn't work?

wysota
2nd June 2007, 20:14
Does class "Dialog" inherit QDialog?

Salazaar
2nd June 2007, 20:35
Yes, I think so. Here are the files
Maker.h

#ifndef MAKER_H
#define MAKER_H

#include "ui_maker.h"



class MainWindow : public QMainWindow, public Ui::MainWindow
{
Q_OBJECT

public:
MainWindow(QMainWindow *parent = 0);

private slots:

void on_actionAbout_triggered();

private:

Ui::MainWindow ui;
};

#endif



About.h

#ifndef ABOUT_H
#define ABOUT_H

#include "ui_about.h"



class Dialog : public QWidget, public Ui::Dialog
{
Q_OBJECT

public:
Dialog(QWidget *parent = 0);


private:

Ui::Dialog ui;
};

#endif



Maker.cpp

#include <QtGui>

#include "maker.h"
#include "about.h"

MainWindow::MainWindow(QMainWindow *parent)
: QMainWindow(parent)
{
ui.setupUi(this);

}

void MainWindow::on_actionAbout_triggered()
{


Dialog dlg( this );



dlg.exec();



}




Dialog::Dialog(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);

}




And also main.cpp, ui_about.h, ui_maker.h which contents are obvious. So, what's wrong in it? Regards

jacek
2nd June 2007, 21:02
So, what's wrong in it?
The compiler told you what's wrong.

Dialog isn't derived directly from QWidget, so you can't invoke QWidget constructor, so this:

Dialog::Dialog(QWidget *parent)
: QWidget(parent)
{
...

should be:

Dialog::Dialog( QWidget *parent )
: QDialog( parent )
{
...

Salazaar
2nd June 2007, 21:38
I've done it, but it didn't solve the problem. Compilation log:
http://allyoucanupload.webshots.com/v/2002174960843080783
Regards

jacek
2nd June 2007, 21:55
In about.h it should be:
class Dialog : public QDialog, public Ui::Dialog

Please paste the error messages into your posts. If you click on the C:\ icon in the corner, a menu will be opened that will allow you to mark and copy the text.

Salazaar
2nd June 2007, 22:00
IT WORKS!!! Special thanks to: jacek, jpn, wysota
Regards

anafor2004
16th January 2008, 13:25
I am new at QT,
I tried to do same thing but i had this mistake.What is the solution? Can you help me?



make x86
qmake -o qMakefile my.pro
make --makefile qMakefile
make[1]: Entering directory `/home/canibek/davinci/software/workspace/denem'
g++ -c -pipe -O2 -D_REENTRANT -Wall -W -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/default -I. -I/usr/include/QtCore -I/usr/include/QtCore -I/usr/include/QtNetwork -I/usr/include/QtNetwork -I/usr/include/QtGui -I/usr/include/QtGui -I/usr/include -Imoc_obj -I. -o moc_obj/main.o main.cpp
In file included from main.cpp:2:
main.h:34:3: warning: no newline at end of file
main.cpp:12:2: warning: no newline at end of file
In file included from main.cpp:3:
dialog1.h:3: error: redefinition of ‘class Dialog’
dialog1.h:4: error: previous definition of ‘class Dialog’
make[1]: Leaving directory `/home/canibek/davinci/software/workspace/denem'
make[1]: *** [moc_obj/main.o] Error 1
make: *** [x86] Error 2

jpn
16th January 2008, 13:30
Missing #ifdef, #define, #endif ?

anafor2004
16th January 2008, 14:01
Thanks JPN, How did I such a simple mistake? I must work harder , Thank you again, I hope some day I will be an expert(Guru) here. :):D