How to get and set QComboBox text
Hi, I am an absolute beginner in Qt. I am trying to make a QComboBox [developer.qt.nokia.com] which is editable, i.e., users can enter text there manually. Now after doing some searching I learned that QComboBox uses QLineEdit [developer.qt.nokia.com] to handle text editing and a pointer to it can be obtained by calling the lineEdit() method of the QComboBox class.
Now I want to set the current text of the QComboBox. To do that, I am trying to use the following piece of code –
- ldt->setText("My Text");
but it’s giving me an error. How can I change the current text of the combo box?
9 replies
welcome to the forum.
You may add items to your QComboBox by using addItem [doc.qt.nokia.com]
The currently selected text you can obtain with currentText [doc.qt.nokia.com]
Well well, something really interesting might have happened here before because today I am writing the same code but there is absolutely no errors, and the text is being set properly.
Could you be a bit more verbose here, please? The actual error message would be quite helpful for an analysis :-)
Since I couldn’t generate the error today, I couldn’t give you the exact description, but it was something like
- Illegal use of type 'struct QLineEdit'........
- ldt->setText("My Text");
Sorry guys, I am again having the same problem. I don’t have a single clue what is happening here. Just a few moments ago I wrote the same code and it worked for me, but now it’s again giving me errors. The first error message is as follows –
mainwindow.cpp:29: error: invalid use of incomplete type ‘struct QLineEdit’
When I double click on this error message the cursor points to the line –
- ldt->setText("My Text");
and the second error message is –
qapplication.h:393: error: forward declaration of ‘struct QLineEdit’
You must log in to post a reply. Not a member yet? Register here!




