Results 1 to 18 of 18

Thread: simple test connection

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2011
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default simple test connection

    i like to help me to do a simple test connexion (i have a button and i like whene i cliced it take the adresse ip and do a test if it's ok it will show me "host is connected" else "host is not connected" .
    so can you help me and give me the code sorce of this app plz i realy need it

  2. #2
    Join Date
    Oct 2010
    Location
    Belarus
    Posts
    71
    Thanks
    1
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Windows Maemo/MeeGo

    Default Re: simple test connection

    Do you want to have button, textedit for IP input and then try connect to host with this IP?

  3. #3
    Join Date
    Mar 2011
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: simple test connection

    yes this is it

  4. #4
    Join Date
    Oct 2010
    Location
    Belarus
    Posts
    71
    Thanks
    1
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Windows Maemo/MeeGo

    Default Re: simple test connection

    Ok. simple example tcp connect to 80 port.

    Qt Code:
    1. void MainWindow::on_pushButton_clicked()
    2. {
    3. ui->label->setText("");
    4. connect(mysocket,SIGNAL(connected()),this,SLOT(on_connected()));
    5. connect(mysocket,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(on_error(QAbstractSocket::SocketError)));
    6. mysocket->connectToHost(ui->lineEdit->text(), 80);
    7. }
    8.  
    9. void MainWindow::on_error(QAbstractSocket::SocketError socketError)
    10. {
    11. ui->label->setText("Not connected " + QString::number(socketError));
    12. }
    13.  
    14. void MainWindow::on_connected()
    15. {
    16. ui->label->setText("It's ok. Connected");
    17. mysocket->disconnectFromHost();
    18. }
    To copy to clipboard, switch view to plain text mode 
    Attached Files Attached Files

  5. #5
    Join Date
    Mar 2011
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: simple test connection

    realy realy thx but i have a erreur:
    it told me:
    QAbstractSocket::SocketError ==> is not a type name
    what i sould do it ?

  6. #6
    Join Date
    Oct 2010
    Location
    Belarus
    Posts
    71
    Thanks
    1
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Windows Maemo/MeeGo

    Default Re: simple test connection

    Xm, try qthelp://com.trolltech.qt.472/qdoc/qabstractsocket.html

    QAbstractSocket::SocketError is not a registered metatype, so for queued connections, you will have to register it with Q_DECLARE_METATYPE() and qRegisterMetaType().

    And QT demo example qthelp://com.trolltech.qt.472/qdoc/network-fortuneclient.html

  7. #7
    Join Date
    Mar 2011
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: simple test connection

    he told me now:
    error: ‘myscoket’ was not declared in this scope

    so what i should do ?

  8. #8
    Join Date
    Oct 2010
    Location
    Belarus
    Posts
    71
    Thanks
    1
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Windows Maemo/MeeGo

    Default Re: simple test connection

    Do you try attach that i do for you?

    mysocket is pointer to QTcpSocket class

  9. #9
    Join Date
    Mar 2011
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: simple test connection

    this time i just like when we push the button he will go to fichier .txt and get the @ ip ligne by ligne and it will do the test
    i'm realy amateur in prog so plz help me

    Qt Code:
    1. void MainWindow::on_pushButton_clicked()
    2. {
    3.  
    4.  
    5. QFile fichier("/home/dousdou/idee.txt");
    6. fichier.open(QIODevice::ReadOnly);
    7. QString contenu = fichier.readAll();
    8. fichier.close();
    9.  
    10.  
    11.  
    12.  
    13. connect(mysocket,SIGNAL(connected()),this,SLOT(on_connected()));
    14. connect(mysocket,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(on_error(QAbstractSocket::SocketError)));
    15. mysocket->connectToHost(contenu, 22);
    16. if (mysocket->waitForConnected(1000))
    17. qDebug("Connected!");
    18.  
    19. };
    To copy to clipboard, switch view to plain text mode 

    but it doesn't work so where is the prb ?

  10. #10
    Join Date
    Oct 2010
    Location
    Belarus
    Posts
    71
    Thanks
    1
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Windows Maemo/MeeGo

    Default Re: simple test connection

    Show /home/dousdou/idee.txt file or attach it, plz
    Try read Qt documentation before ask stupid question.

  11. #11
    Join Date
    Mar 2011
    Posts
    18
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: simple test connection

    it's a file text

Similar Threads

  1. test my QT application
    By anand_2861985 in forum Installation and Deployment
    Replies: 1
    Last Post: 24th November 2010, 10:32
  2. Replies: 1
    Last Post: 2nd April 2010, 06:42
  3. A.I. test. A.I. test.
    By Kumosan in forum General Discussion
    Replies: 3
    Last Post: 19th October 2007, 19:19

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.