Philipp Schmidt wrote:
> Hi,
>
> I have the following Problem. While trying to get Drag&Drop working (only
> accepting items whose ID is not yet in the List) with the mime-type
> "application/x-qabstractitemmodeldatalist" i found that i can't get
> conversion
> between datastreams and items working. The following Listing gives me this
> result:
>
> 1 - test
> 0 -
>
> So what am I doing wrong?
>
> ---- Source ----
> QListWidgetItem i = new QListWidgetItem("test", ui.geschwisterList, 1);
> QDataStream d = new QDataStream();
> i.write(d);
> QListWidgetItem i2 = new QListWidgetItem();
> i2.read(d);
> log.debug(i.type() +" - "+i.text());
> log.debug(i2.type() +" - "+i2.text());
> -------------------
Hi,
Sorry for late reply.
You are using a datastream without a device for both reading and writing
at the same time. Since there is no device the behaviour is more or less
undefined. Instead, use a QByteArray as the device and use a separate
datastream for reading and writing:
import com.trolltech.qt.*;
import com.trolltech.qt.core.*;
import com.trolltech.qt.gui.*;
public class datastream
{
public static void main(String args[]) {
QCoreApplication.initialize(args);
QListWidgetItem i = new QListWidgetItem("test", null, 1);
QByteArray array = new QByteArray();
QDataStream writer = new QDataStream(array,
QIODevice.OpenModeFlag.WriteOnly);
i.write(writer);
QListWidgetItem i2 = new QListWidgetItem();
QDataStream reader = new QDataStream(array,
QIODevice.OpenModeFlag.ReadOnly);
i2.read(reader);
System.out.println(i.type() +" - "+i.text());
System.out.println(i2.type() +" - "+i2.text());
}
}
best regards,
Gunnar
_______________________________________________
Qt-jambi-interest mailing list
[email protected]
http://lists.trolltech.com/mailman/listinfo/qt-jambi-interest