Results 1 to 5 of 5

Thread: A question about a code

  1. #1
    Join Date
    Apr 2011
    Posts
    195
    Thanks
    49
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default A question about a code

    Hi,
    I found this code at a linux program. It is a client - server application and this is a part of the client.
    The communication is ssl encrypted.

    Qt Code:
    1. Client::Client(QString host,long port,bool fs)
    2. {
    3. /*if(!serverConnection)*/ serverConnection = new QSslSocket(this);
    4.  
    5. serverConnection -> setPeerVerifyMode(QSslSocket::QueryPeer);
    6. serverConnection -> setLocalCertificate("mycert.pem");
    7. serverConnection -> setPrivateKey("mycert.pem");
    8. serverConnection -> connectToHostEncrypted( host, port);
    9. peerPort = port;
    10. connected=0;
    11. fileSend=fs;
    12. connect(serverConnection, SIGNAL(encrypted()), SLOT(connectionAccepted()));
    13. connect(serverConnection,SIGNAL(stateChanged(QAbstractSocket::SocketState)),this, SLOT(socketStateChanged(QAbstractSocket::SocketState)));
    14. connect(serverConnection, SIGNAL(readyRead()), this, SLOT(readDataFromServer()));
    15. connect(serverConnection, SIGNAL(disconnected()), serverConnection, SLOT(deleteLater()));
    16. connect(serverConnection, SIGNAL(sslErrors(QList<QSslError>)),SLOT(sslErrors(QList<QSslError>)) );
    17. }
    To copy to clipboard, switch view to plain text mode 
    The programmer calls serverConnection -> connectToHostEncrypted( host, port); and after that he connects the signal encrypted() to the slot connectionAccepted();
    But it should be connected first, shouldn't it?
    Last edited by Qiieha; 13th January 2012 at 12:48.

  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: A question to a code

    No, the signal won't be emitted before the control returns back to the event loop.
    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. The following user says thank you to wysota for this useful post:

    Qiieha (13th January 2012)

  4. #3
    Join Date
    Apr 2011
    Posts
    195
    Thanks
    49
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: A question to a code

    thank u for the reply!

  5. #4
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: A question to a code

    but this is not the general case. If you call a method and something inside it emits synchronously before you have connected, oops, you missed the signal.

    I believe it is better practice to connect before calling methods that can emit.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  6. #5
    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: A question to a code

    The thing is connectToHostEncrypted() doesn't emit. It schedules a connection attempt, just like QWidget::show() doesn't show anything but rather schedules showing the widget.
    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.


Similar Threads

  1. Replies: 2
    Last Post: 9th January 2010, 16:41
  2. Qftp example code question ... hello everyone
    By jrandles in forum Qt Programming
    Replies: 1
    Last Post: 8th February 2008, 21:57
  3. Question about qvector.h code of Qt 4
    By karapas in forum Qt Programming
    Replies: 6
    Last Post: 29th August 2007, 12:27
  4. Example code and metaObject question
    By bruccutler in forum Newbie
    Replies: 1
    Last Post: 12th January 2007, 18:34
  5. a question conerning code in main.cpp
    By nass in forum Qt Programming
    Replies: 1
    Last Post: 19th September 2006, 16:55

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.