Results 1 to 18 of 18

Thread: simple test connection

  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

  12. #12
    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

    Oh. idee.txt contain only one line with IP? Or several?

    For several line try some code:

    Qt Code:
    1. QStringList iplist;
    2. while (!file.atEnd())
    3. {
    4. iplist.append(file.readLine());
    5. }
    6. for(int i=0;i<iplist.count();++i)
    7. {
    8. ...
    9. mysocket->connectToHost(iplist.at(i), 22);
    10. ...
    11. }
    To copy to clipboard, switch view to plain text mode 

    So, you try find not firewalled SSH. it's dirty job.

    Аre you then ask as to help with software for password selection?
    Try read Qt documentation before ask stupid question.

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

    Default Re: simple test connection

    i push the button bute nothing is work (((((((((((((
    Qt Code:
    1. void MainWindow::on_pushButton_clicked()
    2. {
    3. QFile file("/home/dousdou/idee.txt");
    4. QStringList iplist;
    5. while (!file.atEnd())
    6. {
    7. iplist.append(file.readLine());
    8. }
    9.  
    10. for(int i=0;i<iplist.count();++i)
    11. {
    12.  
    13.  
    14. connect(mysocket,SIGNAL(connected()),this,SLOT(on_connected()));
    15. connect(mysocket,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(on_error(QAbstractSocket::SocketError)));
    16. mysocket->connectToHost(iplist.at(i), 22);
    17. if (mysocket->waitForConnected(1000))
    18. qDebug("Connected!");
    19. }
    To copy to clipboard, switch view to plain text mode 

  14. #14
    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

    You don't need use signal and slot if use waitForConnected

    Qt Code:
    1. void MainWindow::on_pushButton_clicked()
    2. {
    3. QFile file("/home/dousdou/idee.txt");
    4. file.open(QIODevice::ReadOnly);
    5. QStringList iplist;
    6. while (!file.atEnd())
    7. {
    8. iplist.append(file.readLine());
    9. }
    10.  
    11. for(int i=0;i<iplist.count();++i)
    12. {
    13. mysocket->connectToHost(iplist.at(i), 22);
    14. if (mysocket->waitForConnected(1000))
    15. qDebug("Connected!");
    16. else qDebug("Error!");
    17. }
    18. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by unit; 7th March 2011 at 16:10.
    Try read Qt documentation before ask stupid question.

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

    Default Re: simple test connection

    I have done what you told me to do but also it doesn't work i know it a simple application and i realy try maney thing but always the some prb it doesn't work so when i execute your code this is what he told me:
    Qt Code:
    1. Démarrage de /home/dousdou/test2-build-desktop/test2...
    2. QMetaObject::connectSlotsByName: No matching signal for on_connected()
    3. QMetaObject::connectSlotsByName: No matching signal for on_error(QAbstractSocket::SocketError)
    4. Error!
    5. Error!
    6. Error!
    7. Error!
    To copy to clipboard, switch view to plain text mode 

  16. #16
    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

    You try to do copy/paste and change part of code without thinking about it. You should read some manuals and src of ready code, and learn what code is do. Try new attach with full code.

    I have next out:

    Qt Code:
    1. Cann't connect to ??10.110.10.22 with error Host not found
    2. Connected to 10.110.10.23
    3. Connected to 10.110.10.9
    4. Cann't connect to 10.110.10.105 with error Socket operation timed out
    5. Cann't connect to 10.110.10.86 with error Socket operation timed out
    To copy to clipboard, switch view to plain text mode 
    Attached Files Attached Files
    Try read Qt documentation before ask stupid question.

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

    Default Re: simple test connection

    i just modify the code like this :
    Qt Code:
    1. MainWindow::~MainWindow()
    2. {
    3. delete ui;
    4. delete mysocket;
    5. }
    6.  
    7. void MainWindow::on_pushButton_clicked()
    8. {
    9. QFile ipfile("/home/dousdou/tech-ip.txt");
    10. if(!ipfile.open(QIODevice::ReadOnly))
    11. {
    12. qDebug("Can't open file");
    13. return;
    14. }
    15. QStringList iplist;
    16. while (!ipfile.atEnd())
    17. {
    18. iplist.append(ipfile.readLine());
    19. }
    20. ipfile.close();
    21. for(int i=0;i<iplist.count();++i)
    22. {
    23. connect(mysocket,SIGNAL(connected()),this,SLOT(on_connected()));
    24. connect(mysocket,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(on_error(QAbstractSocket::SocketError)));
    25. mysocket->connectToHost(iplist.at(i), 22);
    26. }
    27. }
    28. void MainWindow::on_error(QAbstractSocket::SocketError socketError)
    29. {
    30. QMessageBox msgBox;
    31. msgBox.setText("Not connected " + QString::number(socketError));
    32. msgBox.exec();
    33. }
    34.  
    35. void MainWindow::on_connected()
    36. {
    37. QMessageBox msgBox;
    38. msgBox.setText("It's ok. Connected");
    39. msgBox.exec();
    40. mysocket->disconnectFromHost();
    41. }
    To copy to clipboard, switch view to plain text mode 
    and he show me this error:
    Qt Code:
    1. QMetaObject::connectSlotsByName: No matching signal for on_connected()
    2. QMetaObject::connectSlotsByName: No matching signal for on_error(QAbstractSocket::SocketError)
    3. QAbstractSocket::connectToHost() called when already looking up or connecting/connected to "10.20.24.157
    4. "
    5. QAbstractSocket::connectToHost() called when already looking up or connecting/connected to "192.168.1.5
    6. "
    7. QAbstractSocket::connectToHost() called when already looking up or connecting/connected to "10.20.24.155
    8. "
    To copy to clipboard, switch view to plain text mode 
    where is the rpb hier i know that's i'm not good in devlopment but plz i need your help i can work lonly and you are my last chance

  18. #18
    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

    are you kidding me?

    Don't modify my CODE now. Only change path to file and try! Or tell me all your task and i try give you complete code. My Skype is unit_by
    Try read Qt documentation before ask stupid question.

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.