View Full Version : Passing QString from Combobox on main window to second window
willief
8th April 2011, 18:52
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
falconium
8th April 2011, 19:04
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.
willief
8th April 2011, 20:23
ok thank you, that got me started, now here is my issue.
When retrieving the value from my combo box i'm using
connect(ui->comboBox, SIGNAL (activated(const QString)), this, SLOT(dropdownValue(const QString)));
//and the related function:
void dcsTS::dropdownValue(const QString dcmname){
tmpstring = string(dcmname.toAscii()); //tmpstring is a public string variable
}
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. :(
falconium
8th April 2011, 20:55
Why don't you use QString for tmpstring?
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.