Results 1 to 3 of 3

Thread: class and event create

  1. #1
    Join Date
    Oct 2009
    Posts
    30
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default class and event create

    Hi all,

    I have a socket class. I want to catch SocketError.

    1. Method;
    I send QWidget parameter from my class.

    2. Method;
    I create event and i catch this event from main function.

    How can u recommend? And How can I catch this SocketError this socket class and I show my form?

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

    Default Re: class and event create

    3. connect error signal from socket to an appropriate slot in your code.

  3. #3
    Join Date
    Oct 2009
    Posts
    30
    Thanks
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: class and event create

    Thanks for recommend but I don't catch. I connected to SocketErrors signal and my slot is displayError.

    Qt Code:
    1. TcpClient::TcpClient(const QString serverAddress,int serverPort)
    2. {
    3. _serverAddress = serverAddress;
    4. _serverPort = serverPort;
    5. tcpSocket = new QTcpSocket();
    6. connect(tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)),
    7. this, SLOT(displayError(QAbstractSocket::SocketError)));
    8. }
    9. void TcpClient::displayError(QAbstractSocket::SocketError socketError)
    10. {
    11. QString msg;
    12. switch (socketError) {
    13. case QAbstractSocket::RemoteHostClosedError:
    14. break;
    15. case QAbstractSocket::HostNotFoundError:
    16. msg = tr("The host was not found. Please check the "
    17. "host name and port settings.");
    18. break;
    19. case QAbstractSocket::ConnectionRefusedError:
    20. msg = tr("The connection was refused by the peer. "
    21. "Make sure the fortune server is running, "
    22. "and check that the host name and port "
    23. "settings are correct.");
    24. break;
    25. default:
    26. msg = tr("The following error occurred: %1.")
    27. .arg(tcpSocket->errorString());
    28. }
    29. QMessageBox *errorbox = new QMessageBox();
    30. errorbox->setText(msg);
    31. errorbox->show();
    32. }
    To copy to clipboard, switch view to plain text mode 

    But This code is my TcpClient clas. i close server socket and i wait error but not catch. Where I made a mistake?

Similar Threads

  1. Replies: 3
    Last Post: 31st August 2009, 22:50
  2. QThread event handling and QWaitCondition
    By mattc in forum Qt Programming
    Replies: 2
    Last Post: 21st August 2009, 13:00
  3. Custom event gets not propagated to the top level widget
    By nightghost in forum Qt Programming
    Replies: 0
    Last Post: 29th January 2009, 09:06
  4. Notifying Mainwindow of an event..
    By MrGarbage in forum Qt Programming
    Replies: 1
    Last Post: 9th November 2007, 21:29
  5. Problems with Q_OBJECT and subclassing
    By renaissanz in forum Qt Programming
    Replies: 4
    Last Post: 21st February 2006, 22:18

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.