Results 1 to 7 of 7

Thread: assign problem with array of QTcpSocket

  1. #1
    Join Date
    Feb 2010
    Posts
    28
    Qt products
    Qt4
    Platforms
    Windows

    Default assign problem with array of QTcpSocket

    Hi everyboby!

    I have QTcpSocket, QTcpServer arrays, declared as follow:

    QTcpServer *tcpClient;
    QTcpSocket *tcpServer;

    in the constructor:

    tcpServer = new QTcpServer[numConnec];
    tcpClient = new QTcpSocket[numConnec];

    I connected the signal "newConnection" of the first QTcpServer with my slot acceptconnection as follow:

    connect(&tcpServer[0], SIGNAL(newConnection()),SLOT(acceptConnection()), Qt:irectConnection);

    and in the acceptconnection I have:

    &tcpClient[0] = &tcpServer[0].nextPendingConnection();
    connect(&tcpClient[0], SIGNAL(readyRead()),SLOT(startRead0()), Qt:irectConnection);

    I get the following error: '&' requires l-value in the &tcpClient[0] = &tcpServer[0].nextPendingConnection();

    do you know how I'm doing bad?

    Thanks in advance!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: assign problem with array of QTcpSocket

    Qt Code:
    1. &tcpClient[0] = &tcpServer[0].nextPendingConnection();
    To copy to clipboard, switch view to plain text mode 
    This is not a valid (or at least not a useful) C++ statement.

    You probably wanted:
    Qt Code:
    1. tcpClient[0] = tcpServer[0]->nextPendingConnection();
    To copy to clipboard, switch view to plain text mode 

    And consider using QVector or std::vector instead of those C arrays.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Feb 2010
    Posts
    28
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: assign problem with array of QTcpSocket

    well, if a use

    tcpClient[0] = tcpServer[0]->nextPendingConnection();

    I get this error:

    error C2679: binary '=' : no operator found which takes a right-hand operand of type 'QTcpSocket *' (or there is no acceptable conversion)

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: assign problem with array of QTcpSocket

    You are not assigning a QTcpSocket* to a QTcpSocket*.

    Create a list or vector of QTcpSocket* like Wysota said.
    Example QList<QTcpSocket *> mySocketList;

    Add new sockets to that list and use the QList functions to access them.

  5. #5
    Join Date
    Feb 2010
    Posts
    28
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: assign problem with array of QTcpSocket

    ok, thank you very much, I will try it with a list...

  6. #6
    Join Date
    Feb 2010
    Posts
    28
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: assign problem with array of QTcpSocket

    Hi!

    I tried this with the sender() function but I had some trouble.

    in the slot function I have:

    myclass *tcpServerSender = qobject_cast<myclass*>(QObject::sender());

    but this pointer is always NULL, do you have any ideas, how can I get the pointer to the object?

    thanks!

  7. #7
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: assign problem with array of QTcpSocket

    You shouldn't really be using sender() and that ugly type casting. Use QSignalMapper instead.

Similar Threads

  1. declare an array of QSemaphore and array of slot functions
    By radeberger in forum Qt Programming
    Replies: 11
    Last Post: 2nd May 2010, 13:24
  2. Assign a wchar_t array to QString
    By jacky in forum Qt Programming
    Replies: 5
    Last Post: 18th April 2009, 12:28
  3. array of pointers to QtcpSocket
    By gQt in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 16th June 2008, 09:15
  4. boost::assign
    By Sivert in forum General Programming
    Replies: 0
    Last Post: 2nd May 2007, 00:23
  5. I can't assign TableView signals...
    By tomek in forum Newbie
    Replies: 5
    Last Post: 9th January 2006, 21:04

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.