Trolltech Home | Qt-jambi-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-jambi-interest Archive, October 2007
QTcpSocket


Message 1 in thread

Hi all,

I'm currently working with QTcpSocket in Jambi.
In C++ I would use it along the lines of:

socket->connectToHost(host, port, QIODevice::ReadWrite);

The last parameter is default but there are no default parameters in 
Java so using Jambi the above lines become:

QIODevice.OpenMode openMode = new 
QIODevice.OpenMode(QIODevice.OpenModeFlag.ReadWrite);
socket.connectToHost(host, port, openMode);

which make my eyes hurt. Is there an easier way to specify openmode?

Regards
Kasper


Message 2 in thread

Hi, Kasper.

Kasper Fisker wrote:
> Hi all,
>
> I'm currently working with QTcpSocket in Jambi.
> In C++ I would use it along the lines of:
>
> socket->connectToHost(host, port, QIODevice::ReadWrite);
>
> The last parameter is default but there are no default parameters in 
> Java so using Jambi the above lines become:
>
> QIODevice.OpenMode openMode = new 
> QIODevice.OpenMode(QIODevice.OpenModeFlag.ReadWrite);
> socket.connectToHost(host, port, openMode);

In general, Qt Jambi should have a method overload in cases where Qt/C++ 
has a default argument expression. Thus

    socket.connectToHost(host, port);

should have worked and I will make sure it works in the next minor 
release of Qt Jambi (4.4). In addition, functions for which the final 
argument is a flag type will (in general) also have an overload which 
takes an varargs array of the relevant enum type, so that

    socket.connectToHost(host, port, QIODevice.OpenModeFlag.ReadWrite);

should work as well. This means that you will usually not have to 
instantiate the flags as you do in your example, and you will usually 
get the same convenience of default arguments as you do in Qt/C++. 
However, it seems that for the particular method 
QAbstractSocket.connectToHost(), a manual override in our type system 
has caused all these overloads to disappear from the API. This is an 
unfortunate bug, and will be fixed for the next minor release.

My best suggestions for a work-around is:

    import com.trolltech.qt.core.QIODevice.OpenModeFlag;

    // [...]

        socket.connectToHost(host, port, 
OpenModeFlag.createQFlags(OpenModeFlag.ReadWrite));

which may hurt a little bit less to your eyes.


-- Eskil