Results 1 to 10 of 10

Thread: Sending QString to QDialog

  1. #1
    Join Date
    Mar 2008
    Posts
    5
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Sending QString to QDialog

    Hi, if I have someDialog : public QDialog class how do I pass a QString from the main window when I call someDialog->exec()?

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Sending QString to QDialog

    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

  3. #3
    Join Date
    Mar 2008
    Posts
    5
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Sending QString to QDialog

    Qt Code:
    1. Profile *userProfile = new Profile; //the QDialog class
    2. QString strt=currentProfile->text(); //currentProfile is a QAction with text that is something like "some words: username"
    3. strt = strt.section(" ", -1); // I get only the last word
    4.  
    5. userProfile->user = strt; //Maybe this is wrong?
    6. userProfile->exec();
    7. qDebug() << userProfile->user; //The output is "username"
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. Profile::Profile()
    2. {
    3. qDebug() << user; //outputs null string
    4.  
    5. }
    To copy to clipboard, switch view to plain text mode 

    The qDebug() output is
    Qt Code:
    1. ""
    2. "username"
    To copy to clipboard, switch view to plain text mode 

    So the two strings aren't the same. Where's my error?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Sending QString to QDialog

    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.

  5. #5
    Join Date
    Mar 2008
    Posts
    5
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Sending QString to QDialog

    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.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Sending QString to QDialog

    So why do you expect data assigned in operation 3 to be available during operation 1?

  7. #7
    Join Date
    Mar 2008
    Posts
    5
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Sending QString to QDialog

    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?

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Sending QString to QDialog

    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.

  9. The following user says thank you to wysota for this useful post:

    nplus (22nd March 2008)

  10. #9
    Join Date
    Mar 2008
    Posts
    5
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Sending QString to QDialog

    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.

  11. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Sending QString to QDialog

    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:
    1. MyDialog dlg;
    2. dlg.setSomething("xyz"); // this sets the string and adjusts the dialog
    3. dlg.exec();
    To copy to clipboard, switch view to plain text mode 

  12. The following user says thank you to wysota for this useful post:

    nplus (22nd March 2008)

Similar Threads

  1. QString static callback function from CURL
    By tpf80 in forum Qt Programming
    Replies: 12
    Last Post: 16th May 2007, 20:47
  2. Convert from iso-8859-1 to... Something else :-)
    By Nyphel in forum Qt Programming
    Replies: 4
    Last Post: 7th March 2007, 17:59
  3. qt network performance
    By criss in forum Qt Programming
    Replies: 16
    Last Post: 24th July 2006, 09:23
  4. Converting QString to unsigned char
    By salston in forum Qt Programming
    Replies: 3
    Last Post: 24th April 2006, 22:10
  5. [SOLVED] Widget plugin ... how to ?
    By yellowmat in forum Newbie
    Replies: 10
    Last Post: 29th January 2006, 20:41

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.