You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Friday, March 23rd 2007, 10:09am

newbie question re: QInputDialog

Hi,

I'm new to programming in QT, and the simple task I want to do is open a QInputDialog window, get the user's text and have the window close properly. However, when I click on the "OK" or the "close" button (and the QInputDialog window closes), another window immediately opens (one that I'm not aware of creating). This (large) window has nothing in it except for the minimize, maximize, and close icons at the upper right edge of the title bar, and at the left edge of the title bar is the name of the executable. I must click on this second window's close icon for it to go away and for execution to continue. Surely there is a way to use a QInputDialog without having this interfering "phantom" window create itself.

Thanks

Junior

Professional

  • "Junior" is male

Posts: 1,622

Location: San Antonio, TX USA

Occupation: Senior Secure Systems Engineer

  • Send private message

2

Friday, March 23rd 2007, 12:58pm

RE: newbie question re: QInputDialog

Are you using the static method or your own? Are you attaching it to a parent or not? A code snippet would help here along with the version of Qt you are experiening this problem in.

Try just using the static method without assigning a parent to it, it if still happens then you have something being opened in addition to the dialog and the raise is bringing it fore front on the dialog exit.

static example:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
void f()
{
    bool ok;
    QString text;

    text = QInputDialog::getText( 0, "Title", "Label", QLineEdit::Normal, text, &ok, 0 /*assign win/app modal flag?*/ );
    if( ok ) {
        qDebug() << "user pressed ok";
    } else {
         qDebug() << "user pressed cancel";
    }
}

3

Saturday, March 24th 2007, 5:47am

RE: newbie question re: QInputDialog

Junior,

Hello. I'm attaching it to a parent. I appreciate your interest, and here is a snippet of code:

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
FindDialog *dialog = new FindDialog;
app.setMainWidget(dialog);
dialog->show();
cout<<"111111111111111"<<endl;
cout<<"~~~~~~~~~~~~~~~"<<dialog->get_text();
return app.exec();
cout<<"2222222222222222"<<endl;
cout<<"~~~~~~~~~~~~~~~"<<dialog->get_text();
}

-----------------------------------------------------------


FindDialog::FindDialog(QWidget *parent, const char *name)
: QDialog(parent, name) {

bool ok;

QString text = QInputDialog::getText(
tr("Destination change"), tr("Enter the changed destination:"), QLineEdit::Normal,
QString::null, &ok, this );
if ( ok && !text.isEmpty() ) {

// user entered something and pressed OK
cout<< "the text entered was "<<text<<endl;
new_dest=text.latin1();
} else {

// user entered nothing or pressed Cancel

}
}

Junior

Professional

  • "Junior" is male

Posts: 1,622

Location: San Antonio, TX USA

Occupation: Senior Secure Systems Engineer

  • Send private message

4

Monday, March 26th 2007, 1:56pm

RE: newbie question re: QInputDialog

mur_rum,

From your code snippet:

// this is not attached
FindDialog *dialog = new FindDialog;

// this would be attached
FindDialog *dialog = new FindDialog( this, "Find Dialog" );

// However because your calling this within the main app program and I'm assuming this to be Qt 3.x version because of the constructor your using for the FindDialog. What your seeing is the app after the dialog closes. So you need to handle this as well.

Note: statements after return app.exec() will not be called.

Below could be written:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    // 0 - no parent 
    FindDialog *dialog = new FindDialog( 0, "FindDialog";

    // ???? - 
    app.setMainWidget(dialog);

    //  show dialog  (use exec() to make modal )
    //  all input/output data handling should be done by the object class
    //  not here, just present it.
    dialog->show();    

    // because we are in app event loop
    exit( 0 );

    return app.exec();
}



Hope this helps...