Results 1 to 6 of 6

Thread: QDataSream: No Device

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2006
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    1

    Default QDataSream: No Device

    Hi. I'm writing a few small test socket programs using Qt libraries without using the event loop (i.e. no Signals and Slots). Here is the source code for a small server:

    #include <QtNetwork>
    #include <iostream>
    #include <qdatastream.h>

    int main(int *argc, char *argv[]){

    QTcpServer server;
    QTcpSocket *socket;
    server.listen(QHostAddress::LocalHost,8000);
    bool timeout;
    server.waitForNewConnection(50000,&timeout);
    socket=server.nextPendingConnection();
    QDataStream in(socket);
    in.setVersion(QDataStream::Qt_4_0);
    int number;
    in>>number;
    std::cout<<number<<std::endl;
    }

    and a simple client:


    #include <QtNetwork>
    #include <iostream>
    #include <qdatastream.h>

    int main(int *argc, char *argv[]){

    QTcpSocket socket;
    socket.connectToHost(QHostAddress::LocalHost,8000) ;
    if (!socket.waitForConnected(5000)) {
    std::cout<<"Cannot connect to GUI."<<std::endl;
    return 0;
    }
    QDataStream out(&socket);
    out.setVersion(QDataStream::Qt_4_0);
    out<<1;
    }

    when I run the server (receiving data) and then the client, the server displays the message "QDataStream: No device" followed by a zero. What am I doing wrong? thanks.

    Edit: I forgot to note that the client displays the error message "Cannot connect to GUI"
    Last edited by jonging; 20th June 2006 at 20:33.

Similar Threads

  1. Modifying the Display on Device
    By mahe2310 in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 13th April 2006, 04:36
  2. How Qt/Embedded detects the keypad input from device?
    By mahe2310 in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 4th April 2006, 07:08
  3. how to export images of Qt/Embedded on Device
    By mahe2310 in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 23rd March 2006, 12:05
  4. Reading/Writing data from/to usb device
    By yellowmat in forum Newbie
    Replies: 2
    Last Post: 6th March 2006, 13:08
  5. Interaction between QT/Embedded and LCD display device
    By mahe2310 in forum Qt for Embedded and Mobile
    Replies: 4
    Last Post: 22nd February 2006, 09:37

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
  •  
Qt is a trademark of The Qt Company.