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();
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());
}
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());
}
To copy to clipboard, switch view to plain text mode
also I tried to add with following code:
Iterator<MediaFileBean> it = list.iterator();
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()));
}
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()));
}
To copy to clipboard, switch view to plain text mode
"instance" is instance of QTableWidget
Here is link to screenshot: http://www.qtforum.org/index.php?pag...0168a5088fd95c, the las column must be filled completely.
Also I tried this code:
Iterator<MediaFileBean> it = list.iterator();
int row = 0;
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++;
}
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++;
}
To copy to clipboard, switch view to plain text mode
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
A1 A2 A3
B1 B2 B3
C1 C2 C4
To copy to clipboard, switch view to plain text mode
But in result I have
A1 C2 C3
B1 A2 B3
C1 B2 A3
A1 C2 C3
B1 A2 B3
C1 B2 A3
To copy to clipboard, switch view to plain text mode
smth like this
So how to solve the problem, some sugestions
THX
Bookmarks