• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 448
  • Last Modified:

how do you add text to a QCombobox in QT

How do you add text to a QCombobox?  I'm having trouble with the syntax of what I am trying to enter.

I want to add "line1", "line2", and "line3" to my QCombobox.  What are the lines of code that will make this happen?  I don't think this is a difficult question but I can't get the syntax right.

Thanks
0
dwcronin
Asked:
dwcronin
  • 4
  • 3
  • 2
1 Solution
 
mrwad99Commented:
0
 
dwcroninAuthor Commented:
yes -  I can't get it to work.  I tried:

myclassname->insertItem("a",-1);

But it doesn't do anything?
0
 
mrwad99Commented:
>> insertItem

You need to pass a QString (http://www.handhelds.org/~zecke/apidocs/qt/qstring.html) to that function.

Try

QString qString("a");
myclassname->insertItem(qString,-1);
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
dwcroninAuthor Commented:
thank you
0
 
rajeev_devinCommented:
Try this
QComboBox* combo;
combo->addItem ( "line1" );
combo->addItem ( "line2" );
combo->addItem ( "line3" );

If you are using insertItem then do this

combo->insertItem ( 0, "line1" );
combo->insertItem ( 1, "line2" );
combo->insertItem ( 2, "line3" );
0
 
mrwad99Commented:
0
 
rajeev_devinCommented:
Let me clear your confusion :)

This documentation is of old Qt version Qt3
http://www.handhelds.org/~zecke/apidocs/qt/qcombobox.html#613b4b

This documentation is of new Qt version Qt4
http://doc.trolltech.com/4.1/qcombobox.html#insertItem

There is a big change between these two versions.
0
 
rajeev_devinCommented:
But as dwcronin said, he is getting compilation error.
I thought he may be using the newer version Qt4.

But its better to Qt4 than Qt3 as Trolltech has stopped providing support for Qt3.
0
 
mrwad99Commented:
Thanks rajeev_devin :)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now