PDA

View Full Version : Jambi QTableWidget row insert



erani
17th August 2009, 15:42
Hello!

I write an app in Java using Jambi. In application a have a table with some data (list of music files), the problem is that when I am adding data to the table not all data is added if I am using following code:


Iterator<MediaFileBean> it = list.iterator();
QAbstractItemModel model = instance.model();
model.removeRows(0, model.rowCount());


while (it.hasNext()) {
int row = model.rowCount();
model.insertRow(row);
MediaFileBean mf = it.next();
model.setData(row, ALobsterPlaylist.TITLE_INDEX, mf.getTitle());
model.setData(row, ALobsterPlaylist.HIDDEN_INDEX, mf.getFile());
}

also I tried to add with following code:


Iterator<MediaFileBean> it = list.iterator();

QAbstractItemModel model = instance.model();
model.removeRows(0, model.rowCount());


while (it.hasNext()) {
int row = instance.rowCount();
instance.insertRow(row);
MediaFileBean mf = it.next();
instance.setItem(row, ALobsterPlaylist.TITLE_INDEX, new QTableWidgetItem(mf.getTitle()));
instance.setItem(row, ALobsterPlaylist.HIDDEN_INDEX, new QTableWidgetItem(mf.getFile()));
}

"instance" is instance of QTableWidget

Here is link to screenshot: http://www.qtforum.org/index.php?page=Attachment&attachmentID=2171&h=9cb7408ce10488d585203431910168a5088fd95c, the las column must be filled completely.

Also I tried this code:


Iterator<MediaFileBean> it = list.iterator();
int row = 0;
QAbstractItemModel model = instance.model();
model.removeRows(0, model.columnCount());
model.insertRows(0, list.size());

while (it.hasNext()) {
MediaFileBean mf = it.next();
model.setData(row, ALobsterPlaylist.TITLE_INDEX, mf.getTitle());
row++;
}

it = list.iterator();
row = 0;
while (it.hasNext()) {
MediaFileBean mf = it.next();
model.setData(row, ALobsterPlaylist.ARTIST_INDEX, mf.getAuthor());
row++;
}

it = list.iterator();
row = 0;
while (it.hasNext()) {
MediaFileBean mf = it.next();
model.setData(row, ALobsterPlaylist.ALBUM_INDEX, mf.getAlbum());
row++;
}

it = list.iterator();
row = 0;
while (it.hasNext()) {
MediaFileBean mf = it.next();
long m = TimeUnit.MINUTES.convert(mf.getDuration(), TimeUnit.MICROSECONDS);
long s = TimeUnit.SECONDS.convert(mf.getDuration(), TimeUnit.MICROSECONDS);
model.setData(row, ALobsterPlaylist.DURATION_INDEX, m + ":" + (s % 60));
row++;
}

it = list.iterator();
row = 0;
while (it.hasNext()) {
MediaFileBean mf = it.next();

System.out.println(mf.getTitle() + " : " + mf.getFile());

model.setData(row, ALobsterPlaylist.HIDDEN_INDEX, mf.getFile());
row++;
}

It's filling all the rows and columns, but the data in columns is not coresponding to rows.
Ex:
I must have rows


A1 A2 A3
B1 B2 B3
C1 C2 C4


But in result I have

A1 C2 C3
B1 A2 B3
C1 B2 A3
smth like this

So how to solve the problem, some sugestions

THX