Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Find public IP of my internet connection
Forum Updated to NodeBB v4.3 + New Features

Find public IP of my internet connection

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 4 Posters 900 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    markolino_it
    wrote on last edited by
    #1

    Hi to all. Finally i'm opening a new Thread to figure out this problem. I've need to know from my qt code, the public ip iddress of my internet connection.
    I'm using qt (Qt Creator 3.2.1 Based on Qt 5.3.2 (GCC 4.9.2, 32 bit)) on my raspberry and i've already try some solution but unfortunately without success.
    This is the code that i tested, SIGILL signals from the OS coming up...please help me to find a workaround to figure out this problem.

    Widget::Widget(QWidget *parent) :QWidget(parent), ui(new Ui::Widget)
    {
    QEventLoop eventLoop;
    QNetworkAccessManager *netManager = new QNetworkAccessManager(this);
    QUrl url("https://www.whatismyip.org/");
    QNetworkRequest req(url);
    QNetworkReply *reply = netManager->get(req); //this causes error SIGILL
    connect(reply, SIGNAL(finished()), &eventLoop, SLOT(quit()));
    eventLoop.exec();
    //other instructions//
    }
    

    Same problem that i found here : qt forum same problem click

    JonBJ raven-worxR Christian EhrlicherC 3 Replies Last reply
    0
    • M markolino_it

      Hi to all. Finally i'm opening a new Thread to figure out this problem. I've need to know from my qt code, the public ip iddress of my internet connection.
      I'm using qt (Qt Creator 3.2.1 Based on Qt 5.3.2 (GCC 4.9.2, 32 bit)) on my raspberry and i've already try some solution but unfortunately without success.
      This is the code that i tested, SIGILL signals from the OS coming up...please help me to find a workaround to figure out this problem.

      Widget::Widget(QWidget *parent) :QWidget(parent), ui(new Ui::Widget)
      {
      QEventLoop eventLoop;
      QNetworkAccessManager *netManager = new QNetworkAccessManager(this);
      QUrl url("https://www.whatismyip.org/");
      QNetworkRequest req(url);
      QNetworkReply *reply = netManager->get(req); //this causes error SIGILL
      connect(reply, SIGNAL(finished()), &eventLoop, SLOT(quit()));
      eventLoop.exec();
      //other instructions//
      }
      

      Same problem that i found here : qt forum same problem click

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @markolino_it
      Given the behaviour, I thought the workarounds mentioned from the link reference you gave are what is available for RPi? Like they ended up pointing to:

      Based on the thread, I'm assuming the SIGILL is intentional by SSL and harmless since it's trapped somehow.

      ? Obvious question is whether you get the SIGILL when not running under debugger? And second question is do you not get it when not accessing an https address?

      M 1 Reply Last reply
      0
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Don't call QEventLoop, esp. not in ctor of a class but use proper signal/slots instead.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        M 1 Reply Last reply
        1
        • JonBJ JonB

          @markolino_it
          Given the behaviour, I thought the workarounds mentioned from the link reference you gave are what is available for RPi? Like they ended up pointing to:

          Based on the thread, I'm assuming the SIGILL is intentional by SSL and harmless since it's trapped somehow.

          ? Obvious question is whether you get the SIGILL when not running under debugger? And second question is do you not get it when not accessing an https address?

          M Offline
          M Offline
          markolino_it
          wrote on last edited by
          #4

          @JonB said in Find public IP of my internet connection:

          Given the behaviour, I thought the workarounds mentioned from the link reference you gave are what is available for RPi? Like they ended up pointing to:

          Based on the thread, I'm assuming the SIGILL is intentional by SSL and harmless since it's trapped somehow.

          ? Obvious question is whether you get the SIGILL when not running under debugger? And second question is do you not get it when not accessing an https address?

          Thanks for the answer. It is the first time that i use these function to get a reply from the network, so i only used it with under the debugger.
          Out of the debugger no errors coming up with the same code.
          But i can not test the code. How i can print the reply on the qDebug() console for example ? How i can access the ip in the reply ?
          Thanks a lot.

          JonBJ 1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            Don't call QEventLoop, esp. not in ctor of a class but use proper signal/slots instead.

            M Offline
            M Offline
            markolino_it
            wrote on last edited by
            #5

            @Christian-Ehrlicher
            Thanks a lot.

            1 Reply Last reply
            0
            • M markolino_it

              Hi to all. Finally i'm opening a new Thread to figure out this problem. I've need to know from my qt code, the public ip iddress of my internet connection.
              I'm using qt (Qt Creator 3.2.1 Based on Qt 5.3.2 (GCC 4.9.2, 32 bit)) on my raspberry and i've already try some solution but unfortunately without success.
              This is the code that i tested, SIGILL signals from the OS coming up...please help me to find a workaround to figure out this problem.

              Widget::Widget(QWidget *parent) :QWidget(parent), ui(new Ui::Widget)
              {
              QEventLoop eventLoop;
              QNetworkAccessManager *netManager = new QNetworkAccessManager(this);
              QUrl url("https://www.whatismyip.org/");
              QNetworkRequest req(url);
              QNetworkReply *reply = netManager->get(req); //this causes error SIGILL
              connect(reply, SIGNAL(finished()), &eventLoop, SLOT(quit()));
              eventLoop.exec();
              //other instructions//
              }
              

              Same problem that i found here : qt forum same problem click

              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by
              #6

              @markolino_it
              most probably the SIGILL signal is coming from the OpenSSL libs upon initialization.
              you should be able to simply jump over (F5) this signal and continue with your application.

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              0
              • M markolino_it

                @JonB said in Find public IP of my internet connection:

                Given the behaviour, I thought the workarounds mentioned from the link reference you gave are what is available for RPi? Like they ended up pointing to:

                Based on the thread, I'm assuming the SIGILL is intentional by SSL and harmless since it's trapped somehow.

                ? Obvious question is whether you get the SIGILL when not running under debugger? And second question is do you not get it when not accessing an https address?

                Thanks for the answer. It is the first time that i use these function to get a reply from the network, so i only used it with under the debugger.
                Out of the debugger no errors coming up with the same code.
                But i can not test the code. How i can print the reply on the qDebug() console for example ? How i can access the ip in the reply ?
                Thanks a lot.

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #7

                @markolino_it
                If you followed the link you quoted for the same problem, one suggestion at https://forums.raspberrypi.com/viewtopic.php?t=59328&p=814919 is

                Under Tools->Options->Debugger->gdb, Add this in the "Additional Startup Commands" entry box:

                handle SIGILL noprint nostop

                This "fixes" the problem, but ALL SIGILLS will be ignored. Hopefully those that are "real issues" cause something else to happen a few instructions later that's not hard to isolate. Or, just hope you don't have any "real ones" :lol:

                M 1 Reply Last reply
                0
                • JonBJ JonB

                  @markolino_it
                  If you followed the link you quoted for the same problem, one suggestion at https://forums.raspberrypi.com/viewtopic.php?t=59328&p=814919 is

                  Under Tools->Options->Debugger->gdb, Add this in the "Additional Startup Commands" entry box:

                  handle SIGILL noprint nostop

                  This "fixes" the problem, but ALL SIGILLS will be ignored. Hopefully those that are "real issues" cause something else to happen a few instructions later that's not hard to isolate. Or, just hope you don't have any "real ones" :lol:

                  M Offline
                  M Offline
                  markolino_it
                  wrote on last edited by markolino_it
                  #8

                  I'm tryng to test this code without the debugger but unfortunately i can't see any "RESPONSE" printed in the console.

                  QNetworkAccessManager *netManager = new QNetworkAccessManager(this);
                  QUrl url("https://www.whatismyip.org/");
                  QNetworkRequest req(url);
                  QNetworkReply *reply = netManager->get(req); 
                  connect(reply, &QNetworkReply::finished, [=]() {
                  
                          if(reply->error() == QNetworkReply::NoError)
                          {
                              QByteArray response = reply->readAll();
                              qDebug()<< "RESPONSE#########";  //it never comes here
                              // do something with the data...
                          }
                          else // handle error
                          {
                            qDebug()<<reply->errorString();
                          }
                      });
                  
                      reply = netManager->get(req); 
                  
                  JonBJ 1 Reply Last reply
                  0
                  • M markolino_it

                    I'm tryng to test this code without the debugger but unfortunately i can't see any "RESPONSE" printed in the console.

                    QNetworkAccessManager *netManager = new QNetworkAccessManager(this);
                    QUrl url("https://www.whatismyip.org/");
                    QNetworkRequest req(url);
                    QNetworkReply *reply = netManager->get(req); 
                    connect(reply, &QNetworkReply::finished, [=]() {
                    
                            if(reply->error() == QNetworkReply::NoError)
                            {
                                QByteArray response = reply->readAll();
                                qDebug()<< "RESPONSE#########";  //it never comes here
                                // do something with the data...
                            }
                            else // handle error
                            {
                              qDebug()<<reply->errorString();
                            }
                        });
                    
                        reply = netManager->get(req); 
                    
                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #9

                    @markolino_it
                    Put a qDebug() above the reply->readAll(), and more generally put one in as the first statement in the slot-lambda, obviously we first want to know whether it's even getting there.

                    Do you really have two netManager->get(req) as you show? Because the second one overwrites the reply object returned from the first one. Please always post actual code.

                    1 Reply Last reply
                    1
                    • M Offline
                      M Offline
                      markolino_it
                      wrote on last edited by markolino_it
                      #10

                      Finally got it works. I Share my solution.
                      I create a new QWidget Application with a pushButton, so in widget.h :

                      public:
                          explicit Widget(QWidget *parent = 0);
                          ~Widget();
                      
                      private slots:
                          void on_pushButton_clicked();
                          void on_readData();
                      
                      private:
                          Ui::Widget *ui;
                          QNetworkAccessManager *netManager;
                          QNetworkReply *reply;
                      
                      public:
                          explicit Widget(QWidget *parent = 0);
                          ~Widget();
                      
                      private slots:
                          void on_pushButton_clicked();
                          void on_readData();
                      
                      private:
                          Ui::Widget *ui;
                          QNetworkAccessManager *netManager;
                          QNetworkReply *reply;
                      

                      and in widget.cpp

                      Widget::Widget(QWidget *parent) :
                          QWidget(parent),
                          ui(new Ui::Widget)
                      {
                          ui->setupUi(this);
                          netManager = new QNetworkAccessManager(this);
                      }
                      
                      Widget::~Widget()
                      {
                          delete ui;
                      }
                      
                      void Widget::on_pushButton_clicked()
                      {
                          reply = netManager->get(QNetworkRequest(QUrl("https://www.whatismyip.org/")));    
                          connect(reply, SIGNAL(finished()), this, SLOT(on_readData()));
                      }
                      
                      void Widget::on_readData()
                      {   
                          if(reply->error() == QNetworkReply::NoError)
                                  {
                                      QByteArray response = reply->readAll();                  
                                      //All the HTML code (include IP ADDRESS)
                                      qDebug()<< response;
                                  }
                                  else // handle error
                                  {
                                    qDebug()<<reply->errorString();
                                  }
                      }
                      

                      More info at : QtDocumentation
                      I hope that this can help other people !
                      Now i think that i can search for "IP" in the ByteArray and store them in a QString or things like that...
                      Thanks a lot.

                      1 Reply Last reply
                      0
                      • M markolino_it

                        Hi to all. Finally i'm opening a new Thread to figure out this problem. I've need to know from my qt code, the public ip iddress of my internet connection.
                        I'm using qt (Qt Creator 3.2.1 Based on Qt 5.3.2 (GCC 4.9.2, 32 bit)) on my raspberry and i've already try some solution but unfortunately without success.
                        This is the code that i tested, SIGILL signals from the OS coming up...please help me to find a workaround to figure out this problem.

                        Widget::Widget(QWidget *parent) :QWidget(parent), ui(new Ui::Widget)
                        {
                        QEventLoop eventLoop;
                        QNetworkAccessManager *netManager = new QNetworkAccessManager(this);
                        QUrl url("https://www.whatismyip.org/");
                        QNetworkRequest req(url);
                        QNetworkReply *reply = netManager->get(req); //this causes error SIGILL
                        connect(reply, SIGNAL(finished()), &eventLoop, SLOT(quit()));
                        eventLoop.exec();
                        //other instructions//
                        }
                        

                        Same problem that i found here : qt forum same problem click

                        Christian EhrlicherC Offline
                        Christian EhrlicherC Offline
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        @markolino_it Then please mark the topic as solved.

                        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                        Visit the Qt Academy at https://academy.qt.io/catalog

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved