This forum has been archived. All content is frozen. Please use KDE Discuss instead.

QtScript and QTcpSocket

Tags: None
(comma "," separated)
cyberwizzard
Registered Member
Posts
29
Karma
0

QtScript and QTcpSocket

Tue Jan 27, 2009 1:36 pm
I've been over de QtScript API a million times and I keep getting this error:
Code: Select all
Error: QAbstractSocket::connectToHost(): could not find a function match; candidates are:
connectToHost(QHostAddress address, unsigned short port, OpenMode mode)
connectToHost(String hostName, unsigned short port, OpenMode mode)


The function which generates this error is:
Code: Select all
<snip>
this.socket = new QTcpSocket();
      
      // Now connect to LCDd
      Amarok.alert(lcdproc_host+ " "+lcdproc_port);
      //this.socket.connectToHost( lcdproc_host, lcdproc_port, QIODevice.ReadWrite);
      this.socket.connectToHost( "localhost", 13666);
      
      // Wait for connection
      this.socket.waitForConnected(1000);
      
      if(this.socket.isConnected()) {
         // Create a stream for socket IO
         this.stream = new QTextStream(this.socket);
<snip>


I can't get this to work and I can't find a single QtScript example on the internet (or Google is screwing with me).

On a side note: I saw someone in PyQt4 using socket.connect to add signal handlers to the socket. I get errors that the connect function does not exists for a QTcpSocket and according to the most recent docs there is indeed no such function. Is it still possible to trap these events in QtScript?


cyberwizzard
Registered Member
Posts
29
Karma
0

Re: QtScript and QTcpSocket

Wed Jan 28, 2009 2:20 pm
I figured out on my own how to parse XML using the API but the network connections are still an issue:
Code: Select all
Importer.loadQtBinding("qt.core");
Importer.loadQtBinding("qt.script");
Importer.loadQtBinding("qt.network");
var host = new QHostAddress("localhost");
var sock = new QTcpSocket();
var port = 25;
sock.connectToHost(host, port.toUInt16(), QIODevice.ReadWrite);


The qt.script import doesn't seem to do anything but I tried it because I wanted to do this:
Code: Select all
var port = new QScriptValue(25); ... port.toUInt16() ...


Whatever I pass to the function it keeps throwing an error that the prototype is incorrect. The string and QHostAddress didn't seem to matter so I'm concluding that it must be the port parameter. But it seems that every number in QtScript is of the wrong type (I guess its a 32-bit integer)... So despite the claims that you can even open TCP connections from within Amarok - how do you actually do it?


User avatar
eean
KDE Developer
Posts
1016
Karma
0
OS

Re: QtScript and QTcpSocket

Wed Jan 28, 2009 9:58 pm
.toUInt16() isn't a javascript method of integer that I'm familiar with. Adding exception handling catchers to your javascript is sometimes needed to figure out whats going on.

That said, I was poking at this code in the Amarok Script Console and I see your problem. I'll look into this issue.


Amarok Developer
cyberwizzard
Registered Member
Posts
29
Karma
0

Re: QtScript and QTcpSocket

Thu Jan 29, 2009 2:09 pm
As an alternative, it seems that the API can be modified for Amarok QtScript correct? How about making each function with a 16-bit int use a 32-bit constructor for QtScript? You could wrap it around the original one and even throw an exception when for example a unsigned short gets a 1.234.678 value assigned to it...

A direct solution would be even cooler but I sort of exhausted my keyword collection on Google and found nobody with this problem (or the solution) :(


User avatar
eean
KDE Developer
Posts
1016
Karma
0
OS

Re: QtScript and QTcpSocket

Thu Jan 29, 2009 2:38 pm
Well it appears to me like a Qt bindings wrapper bug.  I'm going to prepare a bug report and link it here.


Amarok Developer
User avatar
eean
KDE Developer
Posts
1016
Karma
0
OS

Re: QtScript and QTcpSocket

Thu Jan 29, 2009 2:51 pm
Bug submitted at:
http://code.google.com/p/qtscriptgenera ... d=29&can=1

Thanks for posting sample code and such, makes writing the bug report really easy. :D

Hooopfully we're doing something wrong and it can be worked around. If its a bug then you'd have to wait until Amarok 2.0.2 at the earliest for a fix.

Last edited by Anonymous on Thu Jan 29, 2009 2:54 pm, edited 1 time in total.


Amarok Developer
cyberwizzard
Registered Member
Posts
29
Karma
0

Re: QtScript and QTcpSocket

Thu Jan 29, 2009 3:03 pm
I learned the hard way that figuring out whats wrong with my code is best handled by providing a snippet which blows up :D

Even if it is a bug I don't mind running SVN again, just upgraded last week to stable anyway ;)


cyberwizzard
Registered Member
Posts
29
Karma
0

Re: QtScript and QTcpSocket

Tue Feb 03, 2009 1:07 pm
The ticket has been updated to fixed. I was hoping on a workaround but I suppose this means fixed in SVN... How long will it take to propagate the fix into the Amarok SVN?


User avatar
eean
KDE Developer
Posts
1016
Karma
0
OS

Re: QtScript and QTcpSocket

Tue Feb 03, 2009 10:22 pm
Not long, just have to copy it over.


Amarok Developer
User avatar
eean
KDE Developer
Posts
1016
Karma
0
OS

Re: QtScript and QTcpSocket

Wed Feb 04, 2009 12:50 am
Commited.

Edit: oh yea, thanks for pointing out that Kent fixed it. I hadn't noticed.

Last edited by Anonymous on Wed Feb 04, 2009 1:09 am, edited 1 time in total.


Amarok Developer
apr
Registered Member
Posts
2
Karma
0
OS

Re: QtScript and QTcpSocket

Wed Nov 25, 2009 11:40 pm
I have experienced the same problem, except that the proposed port.toUInt16()
code gives me a "not defined" error.

If you have gotten this to work, please share a complete code snippet of how you did it. Here's my code that fails:

Code: Select all
Importer.loadQtBinding( "qt.core" );
Importer.loadQtBinding( "qt.script" );
Importer.loadQtBinding( "qt.object" );
Importer.loadQtBinding( "qt.xml" );
Importer.loadQtBinding( "qt.network" );
Importer.loadQtBinding( "qt.gui" );

var myhost = new QHostAddress("localhost");
var myport = 9090;
var sock = new QTcpSocket(this);

sock.connectToHost( myhost, myport.toUInt16(), QIODevice.ReadWrite );



Thanks a lot for any help you give.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS

Re: QtScript and QTcpSocket

Thu Nov 26, 2009 5:42 am
You are working differently to the original code sample.
Try changing it as below.
Code: Select all
var myport = new QScriptValue(9090);


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
apr
Registered Member
Posts
2
Karma
0
OS

Re: QtScript and QTcpSocket

Sat Nov 28, 2009 9:19 pm
I get this error:

ReferenceError QScriptValue is not defined.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS

Re: QtScript and QTcpSocket

Sun Nov 29, 2009 9:10 pm
Interestingly it worked for the OP. Unfortunately I do not know much about Javascript / QtScript so I do not know why this error is occurring. Have you tried removing the toUInt16() part?


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
cyberwizzard
Registered Member
Posts
29
Karma
0

Re: QtScript and QTcpSocket

Fri Dec 25, 2009 3:21 pm
Update: it still does not work in the latest stable builds... I wonder if the fix ever was committed to the release branch :)




Bookmarks



Who is online

Registered users: Bing [Bot], gfielding, Google [Bot], markhm, Sogou [Bot], Yahoo [Bot]