PDA

View Full Version : Few newbie questions



Salazaar
1st May 2007, 22:54
Hi all. I've gotta few questions.
----------------------------------------------
1. I have created a main window, complete menus and toolbars, all is good, but I want to make a dialog, which will be called when a user clicks a About button in my menu. Ok, so I have created new dialog, but I can't connect it to the actionAbout (beacuse I saved the dialog in other file). I mean that i can't connect it even if both files are opened in the same time. How can I connect it?
----------------------------------------------
2. How to do it: If a user clicks a save button, program saves LineEdit contents in to a file which user select. And how to make more difficult actions?
----------------------------------------------
3. Finally, how to build a program when everything is designed?

vermarajeev
2nd May 2007, 04:49
Hi all. I've gotta few questions.
----------------------------------------------
1. I have created a main window, complete menus and toolbars, all is good, but I want to make a dialog, which will be called when a user clicks a About button in my menu. Ok, so I have created new dialog, but I can't connect it to the actionAbout (beacuse I saved the dialog in other file). I mean that i can't connect it even if both files are opened in the same time. How can I connect it?
----------------------------------------------
2. How to do it: If a user clicks a save button, program saves LineEdit contents in to a file which user select. And how to make more difficult actions?
----------------------------------------------
3. Finally, how to build a program when everything is designed?

1)
void MainWindow::slotAboutButton()
{
QDialog* dlg = new QDialog(this);
dlg->show();
}
use this connect statement in your mainwindow
connect( btnAction, SIGNAL( clicked() ), this, slotAboutButton() ));
2) Similar way connect clicked signal of save Button to some slot and use QTextStream to save data to a file.
3) It depends what you are using (linux or windows). On windows you can create a vcproject using the pro file and load it. Then there is a build button to build the program.
On linux either you can use kdevelop or just say

qmake test.pro
make
There are many ways to do so.. Please read qtAssistance about qmake you will get an idea about what to do.

Thanks

Salazaar
2nd May 2007, 19:00
Hi. Thanks for your reply. I've gotta question about 2). Where do I have to type this code in qt designer?

jpn
2nd May 2007, 21:06
3. Finally, how to build a program when everything is designed?
Using a Component in Your Application (http://doc.trolltech.com/4.2/designer-using-a-component.html)


2). Where do I have to type this code in qt designer?
How can I add a custom slot in Qt4 Designer? (http://www.qtcentre.org/forum/faq.php?faq=qt_designer_category#faq_qt_designer_s lots_inqt4)

Salazaar
2nd May 2007, 22:00
Yeah, I can't, so how can I do 1) But to make aplications using qt designer I have to have correctly installed this damn qt, what a can't do since march...

vermarajeev
3rd May 2007, 05:18
Yeah, I can't, so how can I do 1) But to make aplications using qt designer I have to have correctly installed this damn qt, what a can't do since march...

What do you mean you have to correctly install qt designer. Isnt it installed?? Tell us the process you followed and we can help you correct. Did you try getting the same output without using qt designer??

sunil.thaha
3rd May 2007, 08:09
void MainWindow::slotAboutButton()
{
QDialog* dlg = new QDialog(this);
dlg->show();
}
use this connect statement in your mainwindow
connect( btnAction, SIGNAL( clicked() ), this, slotAboutButton() ));

What will happen if the button is clisked several times... Do you see something wrong ?

Better solution would be to create the dialog only if it is not created ? this cab be done by making the dlg a data member. in the constructor you can set it to 0.



MainWindow::MainWindow(){
// ....
dlg = 0;
}
[...]
void MainWindow::slotAboutButton()
{
if( dlg == 0 ) {
dlg = new QDialog(this);
}
dlg->show();
dlg->raise();
dlg->activateWindow()
}

vermarajeev
3rd May 2007, 08:39
That was just a sample to give an idea about how it can be solved.

Anyway thanks for correction

Or it can even be done in this way

void MainWindow::slotAboutButton(){
QDialog* dlg = new QDialog(this);
dlg->show();
//No need for qDialog so delete it immediately
delete dlg;
dlg = 0;
}

If you want the instance of dlg later in your progrm then you have to create a member variable as Sunil suggested

Thanks

sunil.thaha
3rd May 2007, 09:39
I would rather create it on Stack than on Heap ;)
And other thing is that show() is a non blocking code. you should use exec instead

Salazaar
3rd May 2007, 20:13
Ok, so I have:
1) Downloaded Qt 4.2.3 Open Source installer
2) Installed it to my Dev-C++ directory
3) Added this (http://darkhack.googlepages.com/Qt4.1-Template.zip) template to my Dev-Cpp/Temaplates
4) Added C:/Qt/4.2.3/lib library and C:/Qt/4.2.3/bin binary file to Dev-C++ by tools->compilator options->directories
That's all. So what I am doing wrong?