PDA

View Full Version : How to pass parameters to a .ui file in Qt?



TheIndependentAquarius
21st August 2012, 10:00
For: http://doc.qt.nokia.com/4.7-snapshot/qcombobox.html#setItemText
I wrote:


<widget class="QComboBox" name = "button55">
<property name="ItemText">
<number>0</number>
<string>fontCombosBox</string>
</property>
</widget>


This results in:

ui_showmap.h:73:109: error: no matching function for call to ‘QComboBox::setItemText(QString)’
../../../../qtsdk-2010.05/qt/include/QtGui/qcombobox.h:206:10: note: candidate is: void QComboBox::setItemText(int, const QString&)


I checked: http://www.kde.gr.jp/~ichi/qt/designer-manual-15.html#1-19

Tried changing string to cstring. That didn't help either.

What's the way out?

P.S. Complier is g++ on openSUSE 11.3 with Qt 4.7

spirit
21st August 2012, 10:13
QComboBox::setItemTex takes 2 parameters, you're passing only one. The compilers complains on such invocation.

TheIndependentAquarius
21st August 2012, 10:16
QComboBox::setItemTex takes 2 parameters, you're passing only one. The compilers complains on such invocation.
I *did* pass two.
First number, second string.

Now, I saw this: http://doc.qt.nokia.com/4.7-snapshot/demos-embeddeddialogs-embeddeddialog-ui.html

so the correct way is:



<widget class="QComboBox" name="zoomLevel" >
<item>
<property name="text" >
<string>5</string>
</property>
</item>
</widget>


Question: Besides, qt functions also have parameter types as "QVariant". If I have to use those parameters what's the way out? Is there any proper documentation on .ui files?

spirit
21st August 2012, 10:18
Qt Designer has convenient QComboBox items editor. Why don't you use it instead of manually editing xml (ui) file?

TheIndependentAquarius
21st August 2012, 10:21
I don't have it installed currently, that's why asked.

spirit
21st August 2012, 10:23
I'm sure you do. :) Check your QTDIR/bin folder. Or if you are using QtCreator there is the "Designer" tab in main window.

TheIndependentAquarius
21st August 2012, 10:26
That's quite helpful. I opened the QtCreator and saw the designer tab. Indeed the .ui gets generated automatically. That's the reason perhaps that there is no proper documentation for it.

spirit
21st August 2012, 10:28
There is documentation but it's not a part of Qt's docs. It's part of the QtCreator's docs. See Developing Widget Based Applications (http://doc.qt.nokia.com/qtcreator-2.5/creator-using-qt-designer.html).