lqt5 / lqt

Lua Binding for Qt5

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

QDataStream

RhettTR opened this issue · comments

It seems to me that the QDataStream binding does not work. I tried to use it in my Drag-and-Drop, something like this:

local offset = mouseEvent:pos()
local byteArray = QtCore.QByteArray.new()
local dataStream = QtCore.QDataStream.new(byteArray, QtCore.QIODevice.WriteOnly)
dataStream = dataStream:IN(offset:x())
dataStream = dataStream:IN(offset:y())
local mimeData = QtCore.QMimeData.new()
mimeData:setData('application/x-alben-counter', byteArray)
drag:setMimeData(mimeData)

I see that readRawData() has not been implemented, which can be seen in qtcore_meta_QDataStream.cpp:

static luaL_Reg lqt_metatable_14469[] = {
  { "version", lqt_dispatcher_version_14469 },
  { "floatingPointPrecision", lqt_dispatcher_floatingPointPrecision_14469 },
  { "setDevice", lqt_dispatcher_setDevice_14469 },
  { "byteOrder", lqt_dispatcher_byteOrder_14469 },
  { "writeBytes", lqt_dispatcher_writeBytes_14469 },
  { "commitTransaction", lqt_dispatcher_commitTransaction_14469 },
  { "IN", lqt_dispatcher_IN_14469 },
  { "OUT", lqt_dispatcher_OUT_14469 },
  { "skipRawData", lqt_dispatcher_skipRawData_14469 },
  { "rollbackTransaction", lqt_dispatcher_rollbackTransaction_14469 },
  { "unsetDevice", lqt_dispatcher_unsetDevice_14469 },
  { "status", lqt_dispatcher_status_14469 },
  { "atEnd", lqt_dispatcher_atEnd_14469 },
  { "setByteOrder", lqt_dispatcher_setByteOrder_14469 },
  { "setVersion", lqt_dispatcher_setVersion_14469 },
  { "startTransaction", lqt_dispatcher_startTransaction_14469 },
  { "abortTransaction", lqt_dispatcher_abortTransaction_14469 },
  { "resetStatus", lqt_dispatcher_resetStatus_14469 },
  { "setStatus", lqt_dispatcher_setStatus_14469 },
  { "new", lqt_dispatcher_new_14469 },
  { "device", lqt_dispatcher_device_14469 },
  { "writeRawData", lqt_dispatcher_writeRawData_14469 },
  { "setFloatingPointPrecision", lqt_dispatcher_setFloatingPointPrecision_14469 },
  { "delete", lqt_delete_14469 },
  { 0, 0 },
}; 

I managed to use the MIME functionality not with QDataStream but by accessing byteArray directly:

function frame:dropEvent(event)
    local mimeData = QtCore.QMimeData.new()
    mimeData = event:mimeData()
    local byteArray = QtCore.QByteArray.new(mimeData:data('application/x-alben-counter'))
    local x = byteArray:mid(0,2):toInt()
    local y = byteArray:mid(2,2):toInt()
    local offset = QtCore.QPoint.new(x, y)
    event:source():move(event:pos() - offset)
    event:accept()
end

I will most likely not need QDataStream in my project, so this issue is not a big one.

int readRawData(char *, int len);
The parameter types of char * are not yet supported, and most >> operators are not supported now, because there is no good way to pass c++ type information from lua to the binding layer.

    QDataStream &operator>>(qint8 &i);
    QDataStream &operator>>(quint8 &i);
    QDataStream &operator>>(qint16 &i);
    QDataStream &operator>>(quint16 &i);
    QDataStream &operator>>(qint32 &i);
    inline QDataStream &operator>>(quint32 &i);
    QDataStream &operator>>(qint64 &i);
    QDataStream &operator>>(quint64 &i);
    QDataStream &operator>>(std::nullptr_t &ptr) { ptr = nullptr; return *this; }

    QDataStream &operator>>(bool &i);
    QDataStream &operator>>(qfloat16 &f);
    QDataStream &operator>>(float &f);
    QDataStream &operator>>(double &f);
    QDataStream &operator>>(char *&str);

Fair enough. I understand the difficulties in going from a typed language like C++ to a type-on-the-fly script language like Lua with a limited number of inherent types.

I recommend do not use scripting unless you really need it. C++ is much better.

I really need scripting because I am making a board game engine, where I want to give the board game developer as much freedom to create the visual aspect (and underlying code) of the board game as possible. Qt + Lua is excellent for this purpose, but a lot of testing for feasibility still has to be done.