tags:

views:

55

answers:

1

Hello,

I'm teaching my self Qt; in the same time I don't want to lose my Java skills in Qt. I stacked in some codes to do it in Qt, I tried many times as well as search in the net.

Code # 1

Object[] names = jList1.getSelectedValues();
String msg = "";
for (Object o : names)
msg += o;

Code # 2

DefaultListModel model;
model = new DefaultListModel();
jList1.setModel(model);

Code # 3

if(!jList1.isSelectionEmpty())
I didn't find Empty method :-(

I'm going to do some Qt's video tutorials on youtube, but before that I need to solve the above codes. If any programmer can help I will be thankful;

Thanks in advance

At the end I would like to thanks the experts who are spent thier value times to help others

A: 

What you want for code #1 and #3 is the selection model. It does not have an empty method, but hasSelection aught to do it for you.

As for code #2, you could use the QStandardItemModel. It could be considered the default model if you must, but having a standard model in most cases defeats the purpose of the model-view paradigm (proving a model interface to your actual data). You could also look into the QList/Tree/TableWidget classes, as they come with a model (which QList/Tree/TableView don't).

e8johan
First of all I'm very happy to hear from youhasSelection serves their purpose, ThanksCode #1 How is to define Object array with no size, Array of Object type in Qt?Code #2I'm using QtableWidget, Below Another NOT working example using Qt QTableWidget *model = new QTableWidget; QString cn[] = {"Hamad","Al Ketbi"}; model = new QtableWidget(cn,0); ui->tableWidget->setModel(model);Many Thanks again
#1, list without size (or rather, size 0): "QList<QObject*> list; list << ", remember that QObjects are not values, they are individuals (http://doc.trolltech.com/4.6/object.html#identity-vs-value). #2 If you want a model of strings, simply use a QStringListModel (http://doc.trolltech.com/4.6/qstringlistmodel.html#details).
e8johan
I will give it try tonight at home, I hope to translate your idea.Sometime I'm asking my self why people help others? it's really kindly from you and the people behind this site
Good luck. As for helping, I think that it is a two fold thing - at least for me - one part is the challenge and development I gain from solving problems, and the other one is the ego bost from success. BTW, if it works, you need to accept answers, a low accept rate lowers the chance of getting more help...
e8johan