Results 1 to 4 of 4

Thread: QObject::connect: Cannot queue arguments of type 'QString&'

  1. #1
    Join Date
    Oct 2007
    Posts
    38
    Thanks
    1

    Default QObject::connect: Cannot queue arguments of type 'QString&'

    Unlike the typical client/server situation, my chat application is both a client and a server. It is a server because it runs an instance of qtcpserver and it is a client, because you can make connections using qtcpsocket.

    To have multiple connections i assumed you need multithreading although I have no experience with multithreading+ I'm new to QT.

    Here is how I'm implementing the ability to establish a connection and then pass off that connection to its own thread.

    Qt Code:
    1. // background info
    2. MSocket tcpSocket;
    3.  
    4. connect(&tcpSocket, SIGNAL(connected()),
    5. this, SLOT(connectionEstablished()));
    6.  
    7. tcpSocket.connectToHost(remoteIP, remotePort);
    8.  
    9. // end background.
    10.  
    11. void MChat::connectionEstablished() {
    12. chatOutput->append("<font color=green>Connection Established.</font>");
    13. MSocketThread* mSockThread = new MSocketThread(tcpSocket.socketDescriptor());
    14. connect(this, SIGNAL(sendText(QString&)),
    15. mSockThread, SIGNAL(sigSend(QString&)));
    16. connect(mSockThread, SIGNAL(relayIncomingText(QString&)),
    17. this, SLOT(outputText(QString&)));
    18. connect(mSockThread, SIGNAL(socketError()),
    19. this, SLOT(error()));
    20. connect(mSockThread, SIGNAL(finished()),
    21. mSockThread, SLOT(deleteLater()));
    22. mSockThread->start();
    23.  
    24. }
    To copy to clipboard, switch view to plain text mode 


    Here's how I'm implementing the MSocketThread

    Qt Code:
    1. void MSocketThread::run() {
    2. MSocket mSocket;
    3. if ( !mSocket.setSocketDescriptor(socketDescriptor) ) {
    4. emit error(mSocket.error());
    5. return;
    6. }
    7. connect(&mSocket, SIGNAL(inboundText(QString&)),
    8. this, SIGNAL(relayIncomingText(QString&)));
    9. connect(this, SIGNAL(sigSend(QString&)),
    10. &mSocket, SLOT(send(QString&)));
    11. /*
    12.   connect(mSocket, SIGNAL(error(QAbstractSocket::SocketError)),
    13. this, SIGNAL(socketError()));
    14.   */
    15. mSocket.waitForDisconnected();
    16.  
    17.  
    18. }
    To copy to clipboard, switch view to plain text mode 

    Finally, here is the problem I'm encountering. When I try to send some chat, the console window displays this message:
    QObject::connect: Cannot queue arguments of type 'QString&'
    (Make sure 'QString&' is registed using qRegisterMetaType().)
    And no chat gets displayed on the remote chat app. output.

    Any tips, solutions, etc. are welcome as I am very new.

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QObject::connect: Cannot queue arguments of type 'QString&'

    To have multiple connections i assumed you need multithreading although I have no experience with multithreading+ I'm new to QT.
    Threading is not something specific to Qt.

    As for the connect problem just pass a QString not a QString& because it is an implicitly shared class, therefore no overhead appears.

  3. #3
    Join Date
    Oct 2007
    Posts
    38
    Thanks
    1

    Default Re: QObject::connect: Cannot queue arguments of type 'QString&'

    Removing all the references it no longer displays that message, but I'm still unable to see the chat I'm receiving (if i'm receiving it at all).

    I'd also really like comments on my architecture. Please point out anything I'm doing that is unnecessary or wrong.

    Threading is not something specific to Qt.
    That's true, I simply said I am new to both QT and multithreading. So expect mistakes!

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QObject::connect: Cannot queue arguments of type 'QString&'

    Passing a non-const reference parameter suggests that you want the receiving function to be able to modify the value and that the modification will affect the passed parameter value. Of course, this is something you cannot do when working with signals and slots across threads. Behind the scenes, parameters, a QString in this case, will be serialized and delivered in a custom event across thread boundaries. Thus, making it non-const reference does not make sense.

    Quote Originally Posted by Dumbledore View Post
    I'd also really like comments on my architecture. Please point out anything I'm doing that is unnecessary or wrong.
    Thanks to the fact that QTcpSocket works asynchronously I'm in serious doubt that you even need an external thread to handle data flow.
    J-P Nurmi

Similar Threads

  1. Replies: 6
    Last Post: 21st September 2007, 13:51
  2. dummy question(Error)
    By Masih in forum Qt Programming
    Replies: 12
    Last Post: 19th July 2007, 23:38
  3. Cannot queue arguments of type 'QStringList'
    By vfernandez in forum Qt Programming
    Replies: 2
    Last Post: 19th April 2006, 20:48

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.