-
Problem displaying my main window
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:
Code:
#include "ui_Maker.h"
int main(int argc, char *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:
Code:
CONFIG += qt
HEADERS += ui_Maker.h
SOURCES += main.cpp
Regards
-
Re: Problem displaying my main window
Please read Using a Component in Your Application. Pay attention to single and multiple inheritance approaches. The direct approach is pretty inflexible and not suggested.
-
Re: Problem displaying my main window
And what should I type:
Code:
#include "ui_Maker.h"
int main(int argc, char *argv[])
{
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
-
Re: Problem displaying my main window
This is the "direct approach" which was suggested against using. But oh well, here goes:
Code:
#include "ui_Maker.h"
int main(int argc, char *argv[])
{
Ui::MainWindow ui;
ui.setupUi(window);
window->show();
return app.exec();
}
PS. Please use the "#"-button for highlighting code blocks.
-
Re: Problem displaying my main window
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
-
Re: Problem displaying my main window
What does the .pro file look like? What's the first error?
-
Re: Problem displaying my main window
This is the .pro file
Code:
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
-
Re: Problem displaying my main window
Quote:
Originally Posted by
Salazaar
This is the .pro file
Code:
CONFIG += qt
HEADERS += ui_Maker.h
SOURCES += main.cpp
Please follow the directions 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.
Quote:
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.
-
Re: Problem displaying my main window
Maybe he should paste only the first few? ;)
And remember about closing the memory leak when you come to this point :)
-
Re: Problem displaying my main window
Quote:
Originally Posted by
wysota
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.. ;)
Quote:
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..
-
Re: Problem displaying my main window
Quote:
Originally Posted by
jpn
Please follow the
directions 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:
Code:
#include <QApplication>
#include <QPushButton>
int main(int argc, char *argv[])
{
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
-
Re: Problem displaying my main window
Quote:
Originally Posted by
Salazaar
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 or multiple inheritance approach and do the changes in the actual widget/dialog/window class (which loads the designed form).
-
Re: Problem displaying my main window
I really don't understand what is described in this link.
-
Re: Problem displaying my main window
Please use the "code" tag (# button) instead of "qtclass" (Qt button) when pasting code.
-
Re: Problem displaying my main window
So how can I connect other dialogs to my main windows action (it is all done with Qt Designer)
-
Re: Problem displaying my main window
-
Re: Problem displaying my main window
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?
-
Re: Problem displaying my main window
Look again at the links JP gave you in post #12.
-
Re: Problem displaying my main window
Hi. I tried to do what's described in http://www.qtcentre.org/forum/faq.ph...esigner_2forms
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...
-
Re: Problem displaying my main window
Please, consider going through the nice tutorials shipped with Qt, starting from Qt Tutorial 1 - Hello World. We are not here to teach you the basics but to help you with problems you may encounter. ;)
-
Re: Problem displaying my main window
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 ;)
-
Re: Problem displaying my main window
I added this:
Code:
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?
-
Re: Problem displaying my main window
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.
-
Re: Problem displaying my main window
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 ;)
-
Re: Problem displaying my main window
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.
-
Re: Problem displaying my main window
Right. Than, I have a question concerning code that jpn gave me:
Code:
#include "ui_Maker.h"
int main(int argc, char *argv[])
{
Ui::MainWindow ui;
ui.setupUi(window);
window->show();
return app.exec();
}
Why it's ? I didn't find anything what should be called by this.
-
Re: Problem displaying my main window
Quote:
Originally Posted by
Salazaar
Why it's
? 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.
-
Re: Problem displaying my main window
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?
-
Re: Problem displaying my main window
Quote:
Originally Posted by
Salazaar
and this MainWindow is the name of my main window which I gave to it by designer, right?
That's right.
-
1 Attachment(s)
Re: Problem displaying my main window
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.
-
Re: Problem displaying my main window
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/designe...tance-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
-
Re: Problem displaying my main window
Quote:
Originally Posted by
Salazaar
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.
Look at the Calculator Form Example. It uses the single inheritance approach and custom slots.
-
Re: Problem displaying my main window
Quote:
Originally Posted by
Salazaar
And to not to make a new thread, I'll ask here, can I create slots in designer?
http://www.qtcentre.org/forum/faq.ph...igner_category
-
Re: Problem displaying my main window
Quote:
Originally Posted by
jpn
But in http://doc.trolltech.com/4.2/designe...tance-approach it shows how to add a custom slot, but it doesn't show how to connect action to another dialog
-
Re: Problem displaying my main window
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.
-
Re: Problem displaying my main window
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:
Code:
#include <QtGui>
#include "maker.h"
{
ui.setupUi(this);
}
void MainWindow::abcziom()
{
}
void MainWindow::cbaziom()
{
)
-
Re: Problem displaying my main window
Could you post the contents of maker.h file?
-
Re: Problem displaying my main window
You have a right bracket instead of a right brace in the last line.
-
Re: Problem displaying my main window
This is the full maker.h content:
Code:
#ifndef MAKER_H
#define MAKER_H
#include "ui_maker.h"
{
Q_OBJECT
public:
private slots:
void abcziom();
void cbaziom();
private:
Ui::MainWindow ui;
};
#endif
So, what's wrong?
-
Re: Problem displaying my main window
As I said, you have a wrong character in your implementation file.
-
Re: Problem displaying my main window
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
-
Re: Problem displaying my main window
Quote:
Originally Posted by
Salazaar
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:
Code:
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.
Quote:
Originally Posted by
Salazaar
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.
-
Re: Problem displaying my main window
Ok, so I create slot:
Code:
void MainWindow::on_actionAbout_triggered()
{
OtherDialog dlg( this );
dlg.exec();
}
And, what's the next step?
-
Re: Problem displaying my main window
Can't you just follow a tutorial or something? It'll be way faster if you do...
-
Re: Problem displaying my main window
Quote:
Originally Posted by
Salazaar
Because I can't understand multiple inheritance
So I'd like you to show me how to do it, please.Regarsds
-
Re: Problem displaying my main window
Quote:
Originally Posted by
Salazaar
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?
-
Re: Problem displaying my main window
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/designe...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.
-
Re: Problem displaying my main window
Quote:
Originally Posted by
jacek
Qt will handle the rest, provided that you have that OtherDialog class.
You're assuming he has a actionAbout action in his class :)
-
Re: Problem displaying my main window
Quote:
Originally Posted by
jacek
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
-
Re: Problem displaying my main window
Quote:
Originally Posted by
jacek
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:
Code:
#ifndef MAKER_H
#define MAKER_H
#include "ui_maker.h"
{
Q_OBJECT
public:
private slots:
void abcziom();
void cbaziom();
private:
Ui::MainWindow ui;
};
#endif
and ui_about:
Code:
#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:
{
Dialog
->setObjectName
(QString::fromUtf8("Dialog"));
label
->setObjectName
(QString::fromUtf8("label"));
label
->setGeometry
(QRect(15,
23,
361,
16));
label->setLayoutDirection(Qt::LeftToRight);
label->setTextFormat(Qt::AutoText);
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::AlignTop);
label_2->setWordWrap(true);
label_3
->setObjectName
(QString::fromUtf8("label_3"));
label_3
->setGeometry
(QRect(25,
163,
171,
21));
pushButton
->setObjectName
(QString::fromUtf8("pushButton"));
pushButton
->setGeometry
(QRect(260,
250,
75,
23));
pushButton->setDefault(true);
pushButton->setFlat(false);
retranslateUi(Dialog);
size = size.expandedTo(Dialog->minimumSizeHint());
Dialog->resize(size);
QObject::connect(pushButton,
SIGNAL(clicked
()), Dialog,
SLOT(close
()));
} // setupUi
void retranslateUi
(QDialog *Dialog
) {
label_3
->setText
(QApplication::translate("Dialog",
"Thank you for using TimeTable Maker",
0,
QApplication::UnicodeUTF8));
Q_UNUSED(Dialog);
} // retranslateUi
};
namespace Ui {
class Dialog: public Ui_Dialog {};
} // namespace Ui
#endif // UI_ABOUT_H