Results 1 to 5 of 5

Thread: QTcpServer and QThread signal/slot problem

  1. #1
    Join Date
    Jun 2008
    Posts
    24
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QTcpServer and QThread signal/slot problem

    Hi.

    I'm trying to implement tcpserver which runs alongside the GUI program. Here are the classes:

    MainWindow:
    Qt Code:
    1. MainWindow::MainWindow()
    2. {
    3. serverThread = new ServerThread(this);
    4. serverThread->start();
    5. }
    To copy to clipboard, switch view to plain text mode 

    ServerThread(QThread):
    Qt Code:
    1. void ServerThread::run()
    2. {
    3. server = new Server(NULL);
    4. server->listen(QHostAddress::Any, DEF_PORT);
    5. //How to connect MainWindow slots with Server signals?
    6. exec();
    7. }
    To copy to clipboard, switch view to plain text mode 

    Server(QTcpServer):
    Qt Code:
    1. Server::Server(QObject *parent) : QTcpServer(parent)
    2. {
    3. connect(this, SIGNAL(newConnection()), this, SLOT(addConnection()));
    4. }
    To copy to clipboard, switch view to plain text mode 

    How do I connect MainWindow slots with Server signals and am I doing this the right way?
    Last edited by Diph; 28th July 2009 at 14:54. Reason: updated contents

  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: QTcpServer and QThread signal/slot problem

    What's the purpose of having the server in a dedicated thread?
    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
    Jun 2008
    Posts
    24
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTcpServer and QThread signal/slot problem

    Quote Originally Posted by wysota View Post
    What's the purpose of having the server in a dedicated thread?
    MainWindow is basically a music player and the server sends playback information etc. to the client. So I can use just signals and slots? The GUI doesn't freeze?

  4. #4
    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: QTcpServer and QThread signal/slot problem

    No, the GUI will be fine, you can use a single thread.
    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.


  5. The following user says thank you to wysota for this useful post:

    Diph (28th July 2009)

  6. #5
    Join Date
    Jun 2008
    Posts
    24
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTcpServer and QThread signal/slot problem

    Quote Originally Posted by wysota View Post
    No, the GUI will be fine, you can use a single thread.
    Ok, thanks.

Similar Threads

  1. QTcpServer + QThread
    By Alex Snet in forum Qt Programming
    Replies: 2
    Last Post: 14th April 2009, 21:46
  2. QTcpSocket, QTcpServer problem
    By frido in forum Qt Programming
    Replies: 3
    Last Post: 3rd April 2009, 23:16
  3. QThread and QTcpSocket
    By ^NyAw^ in forum Qt Programming
    Replies: 3
    Last Post: 12th May 2008, 13:06
  4. QThread + QTcpServer
    By Fastman in forum Qt Programming
    Replies: 4
    Last Post: 19th July 2007, 16:19
  5. Replies: 3
    Last Post: 11th May 2006, 00:00

Tags for this Thread

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.