Hi, if I have someDialog : public QDialog class how do I pass a QString from the main window when I call someDialog->exec()?
Hi, if I have someDialog : public QDialog class how do I pass a QString from the main window when I call someDialog->exec()?
QDialog::exec() does not take arbitrary parameters so make it a member variable and provide a getter and/or setter for it..
J-P Nurmi
Qt Code:
Profile *userProfile = new Profile; //the QDialog class QString strt=currentProfile->text(); //currentProfile is a QAction with text that is something like "some words: username" strt = strt.section(" ", -1); // I get only the last word userProfile->user = strt; //Maybe this is wrong? userProfile->exec(); qDebug() << userProfile->user; //The output is "username"To copy to clipboard, switch view to plain text mode
Qt Code:
Profile::Profile() { qDebug() << user; //outputs null string }To copy to clipboard, switch view to plain text mode
The qDebug() output is
So the two strings aren't the same. Where's my error?
Tell me one thing, what is the execution order of the following four statements in your code:
1. x = userProfile->user;
2. QDialog userProfile;
3. userProfile->user = y;
4. userProfile->exec();
Last edited by wysota; 21st March 2008 at 16:14.
The first piece of code is in one function. The order is:
1. QDialog definition
2. Parsing the string
3. modifying userProfile->user
4. exec()
Last edited by nplus; 21st March 2008 at 17:11.
So why do you expect data assigned in operation 3 to be available during operation 1?
Shouldn't it be available during operatin 4 - userProfile->exec() ? At least how can I assign userProfile->user when userProfile isn't declared? Can you give me an example?
Sure, but the constructor is not called during exec(), right? So accessing it in the constructor will return the value from before you assigned the value.
If you access it at the right time, it will be there.
nplus (22nd March 2008)
Oh, I haven't noticed that. So what's the right implementation then?
Edit: I managed to get it, problem solved. Thanks.
Last edited by nplus; 22nd March 2008 at 18:29.
It depends what you want to do... I guess you should have some method that performs adjustments to the dialog after you change the variable and before exec is called. Actually you should change that variable through the same method instead of operating on it directly.
Qt Code:
MyDialog dlg; dlg.setSomething("xyz"); // this sets the string and adjusts the dialog dlg.exec();To copy to clipboard, switch view to plain text mode
nplus (22nd March 2008)
Bookmarks