Results 1 to 4 of 4

Thread: Passing QString from Combobox on main window to second window

  1. #1
    Join Date
    Feb 2011
    Posts
    12
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Passing QString from Combobox on main window to second window

    Hi all,

    I have a main window with a push button and a combo box on it, currently, when I click the push button, it opens a new Table window that displays values. The values are based on an argument passed from the command line at the moment. I would like to change it so that the values are based on a user input from a Qcombobox, but I can't figure out how to pass the value between the two windows, any ideas?

    Thanks

  2. #2
    Join Date
    May 2010
    Posts
    86
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Passing QString from Combobox on main window to second window

    Try to create a public function in main class, e.g. QString getCurrentComboBoxItem().
    You can access it from the object that is instantiated in main class by using a pointer pointing to main class object.


    Added after 4 minutes:


    Or you can modify the constructor of new window to accept an additional input variable. E.g. TableWindow x = new TableWindow(this, textfromcombobox);.
    So this way you can pass the info down in the hierarchy. Upper one is a solution to read data of main class from subclass occasionally when there is a need, and based on changes inside the subclass.
    Last edited by falconium; 8th April 2011 at 19:04.

  3. #3
    Join Date
    Feb 2011
    Posts
    12
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Passing QString from Combobox on main window to second window

    ok thank you, that got me started, now here is my issue.
    When retrieving the value from my combo box i'm using

    Qt Code:
    1. connect(ui->comboBox, SIGNAL (activated(const QString)), this, SLOT(dropdownValue(const QString)));
    2.  
    3. //and the related function:
    4. void dcsTS::dropdownValue(const QString dcmname){
    5.  
    6. tmpstring = string(dcmname.toAscii()); //tmpstring is a public string variable
    7.  
    8. }
    To copy to clipboard, switch view to plain text mode 

    Now when in the other class I make an instance of dcsTS and try to access tmpstring which is a public variable. That works out fine, except that the string is empty!!

    Any ideas about how to fix this?

    also: I've tried using tmpstring as a char* and making a QByteArray and converting that to a char* and then inside the other class accessing tmpstring and converting it to a real string but when I do that I just get unreadable characters and nonsense in my string.

  4. #4
    Join Date
    May 2010
    Posts
    86
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Passing QString from Combobox on main window to second window

    Why don't you use QString for tmpstring?

Similar Threads

  1. Replies: 2
    Last Post: 17th February 2011, 13:30
  2. Replies: 3
    Last Post: 23rd December 2010, 07:55
  3. Replies: 2
    Last Post: 4th August 2010, 20:10
  4. Replies: 9
    Last Post: 16th May 2010, 17:21
  5. Replies: 11
    Last Post: 11th August 2008, 10:14

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.