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. inet_pton 443: error: 'inet_pton' was not declared in this scope

inet_pton 443: error: 'inet_pton' was not declared in this scope

Scheduled Pinned Locked Moved Unsolved General and Desktop
windows 10network
17 Posts 3 Posters 8.2k Views
  • 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.
  • I Offline
    I Offline
    Imran Hassan
    wrote on last edited by
    #1

    Hello everyone,

    I am trying to use inet_pton in QT but it is giving error 'inet_pton' was not declared in this scope

    I am working in windows10, QT version 5.14.2 with mingw73_64. I have added the library and header files as below

    LIBS += -lws2_32
    
    #include <winsock2.h>
    #include <winsock.h>
    #include <ws2tcpip.h>
    

    and using function as

    inet_pton(AF_INET, "192.168.6.166", destAddr);
    

    I am getting this error 443: error: 'inet_pton' was not declared in this scope
    inet_pton(AF_INET, "192.168.6.166", destAddr);

    Any help will be appreciated
    Regards

    jsulmJ 1 Reply Last reply
    0
    • I Imran Hassan

      Hello everyone,

      I am trying to use inet_pton in QT but it is giving error 'inet_pton' was not declared in this scope

      I am working in windows10, QT version 5.14.2 with mingw73_64. I have added the library and header files as below

      LIBS += -lws2_32
      
      #include <winsock2.h>
      #include <winsock.h>
      #include <ws2tcpip.h>
      

      and using function as

      inet_pton(AF_INET, "192.168.6.166", destAddr);
      

      I am getting this error 443: error: 'inet_pton' was not declared in this scope
      inet_pton(AF_INET, "192.168.6.166", destAddr);

      Any help will be appreciated
      Regards

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Imran-Hassan said in inet_pton 443: error: 'inet_pton' was not declared in this scope:

      I am getting this error 443: error: 'inet_pton' was not declared in this scope

      Is this the only error you get, or is there an error that ws2tcpip.h could not be found?
      Are these includes in the same file where you call inet_pton?

      Also, according to https://docs.microsoft.com/en-us/windows/win32/api/ws2tcpip/nf-ws2tcpip-inet_pton it should be

      #include <Ws2tcpip.h>
      

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      I 2 Replies Last reply
      1
      • jsulmJ jsulm

        @Imran-Hassan said in inet_pton 443: error: 'inet_pton' was not declared in this scope:

        I am getting this error 443: error: 'inet_pton' was not declared in this scope

        Is this the only error you get, or is there an error that ws2tcpip.h could not be found?
        Are these includes in the same file where you call inet_pton?

        Also, according to https://docs.microsoft.com/en-us/windows/win32/api/ws2tcpip/nf-ws2tcpip-inet_pton it should be

        #include <Ws2tcpip.h>
        
        I Offline
        I Offline
        Imran Hassan
        wrote on last edited by
        #3

        @jsulm said in inet_pton 443: error: 'inet_pton' was not declared in this scope:

        Is this the only error you get, or is there an error that ws2tcpip.h could not be found?

        I am getting only this error. It is not giving any error related to the library and header file.

        This is the full error I am getting
        Full error is Sementic Issue 443:9 C:\Users\IMRANHASSAN\Documents\VideoCodecApp\mainwindow.cpp:443: error: 'inet_pton' was not declared in this scope inet_pton(AF_INET, "192.168.6.166", destAddr); ^~~~~~~~~

        jsulmJ 1 Reply Last reply
        0
        • I Imran Hassan

          @jsulm said in inet_pton 443: error: 'inet_pton' was not declared in this scope:

          Is this the only error you get, or is there an error that ws2tcpip.h could not be found?

          I am getting only this error. It is not giving any error related to the library and header file.

          This is the full error I am getting
          Full error is Sementic Issue 443:9 C:\Users\IMRANHASSAN\Documents\VideoCodecApp\mainwindow.cpp:443: error: 'inet_pton' was not declared in this scope inet_pton(AF_INET, "192.168.6.166", destAddr); ^~~~~~~~~

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Imran-Hassan You did not answer this question: "Are these includes in the same file where you call inet_pton?"

          https://forum.qt.io/topic/113070/qt-code-of-conduct

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

            And please try to move the winapi includes before the Qt includes to see if it helps.
            Also try to create a simple main.cpp where you only call inet_pton() to see if it works there.

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

            I 1 Reply Last reply
            1
            • jsulmJ jsulm

              @Imran-Hassan You did not answer this question: "Are these includes in the same file where you call inet_pton?"

              I Offline
              I Offline
              Imran Hassan
              wrote on last edited by
              #6

              @jsulm said in inet_pton 443: error: 'inet_pton' was not declared in this scope:

              "Are these includes in the same file where you call inet_pton?"

              Yes these are included in the same file. I checked it by both including in a header file and include that header file

              Also just including the header files in same file both give the same error

              1 Reply Last reply
              0
              • jsulmJ jsulm

                @Imran-Hassan said in inet_pton 443: error: 'inet_pton' was not declared in this scope:

                I am getting this error 443: error: 'inet_pton' was not declared in this scope

                Is this the only error you get, or is there an error that ws2tcpip.h could not be found?
                Are these includes in the same file where you call inet_pton?

                Also, according to https://docs.microsoft.com/en-us/windows/win32/api/ws2tcpip/nf-ws2tcpip-inet_pton it should be

                #include <Ws2tcpip.h>
                
                I Offline
                I Offline
                Imran Hassan
                wrote on last edited by
                #7

                @jsulm said in inet_pton 443: error: 'inet_pton' was not declared in this scope:

                Is this the only error you get, or is there an error that ws2tcpip.h could not be found?

                Some time it also give this error

                C:\Users\IMRANHASSAN\Documents\VideoCodecApp\mainwindow.cpp:450: error: use of undeclared identifier 'inet_pton'

                1 Reply Last reply
                0
                • Christian EhrlicherC Christian Ehrlicher

                  And please try to move the winapi includes before the Qt includes to see if it helps.
                  Also try to create a simple main.cpp where you only call inet_pton() to see if it works there.

                  I Offline
                  I Offline
                  Imran Hassan
                  wrote on last edited by
                  #8

                  @Christian-Ehrlicher said in inet_pton 443: error: 'inet_pton' was not declared in this scope:

                  And please try to move the winapi includes before the Qt includes to see if it helps.

                  I tried this but same problem

                  Also try to create a simple main.cpp where you only call inet_pton() to see if it works there.

                  I made simple application

                  #include "mainwindow.h"
                  #include "ui_mainwindow.h"
                  
                  
                  
                  //#include <winsock2.h>
                  //#include <winsock.h>
                  #include <ws2tcpip.h>
                  
                  MainWindow::MainWindow(QWidget *parent)
                      : QMainWindow(parent)
                      , ui(new Ui::MainWindow)
                  {
                      ui->setupUi(this);
                      PVOID* destAddr = new PVOID;
                  //    sockaddr_storage storage;
                      inet_pton(AF_INET, "192.168.6.166", destAddr);
                  }
                  
                  MainWindow::~MainWindow()
                  {
                      delete ui;
                  }
                  

                  .pro file is as

                  QT       += core gui
                  
                  greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
                  
                  CONFIG += c++17
                  LIBS += -lws2_32
                  
                  # The following define makes your compiler emit warnings if you use
                  # any Qt feature that has been marked deprecated (the exact warnings
                  # depend on your compiler). Please consult the documentation of the
                  # deprecated API in order to know how to port your code away from it.
                  DEFINES += QT_DEPRECATED_WARNINGS
                  
                  # You can also make your code fail to compile if it uses deprecated APIs.
                  # In order to do so, uncomment the following line.
                  # You can also select to disable deprecated APIs only up to a certain version of Qt.
                  #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
                  
                  SOURCES += \
                      main.cpp \
                      mainwindow.cpp
                  
                  HEADERS += \
                      mainwindow.h
                  
                  FORMS += \
                      mainwindow.ui
                  
                  # Default rules for deployment.
                  qnx: target.path = /tmp/$${TARGET}/bin
                  else: unix:!android: target.path = /opt/$${TARGET}/bin
                  !isEmpty(target.path): INSTALLS += target
                  

                  But the error is same

                  jsulmJ 1 Reply Last reply
                  0
                  • I Imran Hassan

                    @Christian-Ehrlicher said in inet_pton 443: error: 'inet_pton' was not declared in this scope:

                    And please try to move the winapi includes before the Qt includes to see if it helps.

                    I tried this but same problem

                    Also try to create a simple main.cpp where you only call inet_pton() to see if it works there.

                    I made simple application

                    #include "mainwindow.h"
                    #include "ui_mainwindow.h"
                    
                    
                    
                    //#include <winsock2.h>
                    //#include <winsock.h>
                    #include <ws2tcpip.h>
                    
                    MainWindow::MainWindow(QWidget *parent)
                        : QMainWindow(parent)
                        , ui(new Ui::MainWindow)
                    {
                        ui->setupUi(this);
                        PVOID* destAddr = new PVOID;
                    //    sockaddr_storage storage;
                        inet_pton(AF_INET, "192.168.6.166", destAddr);
                    }
                    
                    MainWindow::~MainWindow()
                    {
                        delete ui;
                    }
                    

                    .pro file is as

                    QT       += core gui
                    
                    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
                    
                    CONFIG += c++17
                    LIBS += -lws2_32
                    
                    # The following define makes your compiler emit warnings if you use
                    # any Qt feature that has been marked deprecated (the exact warnings
                    # depend on your compiler). Please consult the documentation of the
                    # deprecated API in order to know how to port your code away from it.
                    DEFINES += QT_DEPRECATED_WARNINGS
                    
                    # You can also make your code fail to compile if it uses deprecated APIs.
                    # In order to do so, uncomment the following line.
                    # You can also select to disable deprecated APIs only up to a certain version of Qt.
                    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
                    
                    SOURCES += \
                        main.cpp \
                        mainwindow.cpp
                    
                    HEADERS += \
                        mainwindow.h
                    
                    FORMS += \
                        mainwindow.ui
                    
                    # Default rules for deployment.
                    qnx: target.path = /tmp/$${TARGET}/bin
                    else: unix:!android: target.path = /opt/$${TARGET}/bin
                    !isEmpty(target.path): INSTALLS += target
                    

                    But the error is same

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @Imran-Hassan You did not really do what @Christian-Ehrlicher suggested...

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

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

                      And why do you not use QtNetwork for it?

                      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
                      • jsulmJ jsulm

                        @Imran-Hassan You did not really do what @Christian-Ehrlicher suggested...

                        I Offline
                        I Offline
                        Imran Hassan
                        wrote on last edited by
                        #11

                        @jsulm said in inet_pton 443: error: 'inet_pton' was not declared in this scope:

                        You did not really do what @Christian-Ehrlicher suggested...

                        I created a simple application with GUI and I also created simple console application. But in both I get same error

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

                          @Imran-Hassan said in inet_pton 443: error: 'inet_pton' was not declared in this scope:

                          and I also created simple console application.

                          Please show the code

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

                          I 1 Reply Last reply
                          0
                          • Christian EhrlicherC Christian Ehrlicher

                            @Imran-Hassan said in inet_pton 443: error: 'inet_pton' was not declared in this scope:

                            and I also created simple console application.

                            Please show the code

                            I Offline
                            I Offline
                            Imran Hassan
                            wrote on last edited by
                            #13

                            @Christian-Ehrlicher said in inet_pton 443: error: 'inet_pton' was not declared in this scope:

                            Please show the code

                            Here is code

                            #include <ws2tcpip.h>
                            #include <QCoreApplication>
                            #include <QtNetwork>
                            
                            
                            
                            int main(int argc, char *argv[])
                            {
                                QCoreApplication a(argc, argv);
                                PVOID* destAddr = new PVOID;
                            //    sockaddr_storage storage;
                                inet_pton(AF_INET, "192.168.6.166", destAddr);
                                return a.exec();
                            }
                            

                            Pro file is

                            LIBS += -lws2_32
                            QT -= gui
                            QT += network
                            CONFIG += c++11 console
                            CONFIG -= app_bundle
                            
                            
                            DEFINES += QT_DEPRECATED_WARNINGS
                            
                            
                            SOURCES += \
                                    main.cpp
                            
                            # Default rules for deployment.
                            qnx: target.path = /tmp/$${TARGET}/bin
                            else: unix:!android: target.path = /opt/$${TARGET}/bin
                            !isEmpty(target.path): INSTALLS += target
                            
                            1 Reply Last reply
                            0
                            • Christian EhrlicherC Offline
                              Christian EhrlicherC Offline
                              Christian Ehrlicher
                              Lifetime Qt Champion
                              wrote on last edited by Christian Ehrlicher
                              #14

                              Ok, so according to the docs you must define _WIN32_WINNT to 0x0600 or higher:

                              Minimum supported client 	Windows 8.1, Windows Vista [desktop apps | UWP apps]
                              

                              I still would suggest you to simply use QtNetwork for this instead some low-level api calls.

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

                              I 1 Reply Last reply
                              2
                              • Christian EhrlicherC Christian Ehrlicher

                                Ok, so according to the docs you must define _WIN32_WINNT to 0x0600 or higher:

                                Minimum supported client 	Windows 8.1, Windows Vista [desktop apps | UWP apps]
                                

                                I still would suggest you to simply use QtNetwork for this instead some low-level api calls.

                                I Offline
                                I Offline
                                Imran Hassan
                                wrote on last edited by
                                #15

                                @Christian-Ehrlicher said in inet_pton 443: error: 'inet_pton' was not declared in this scope:

                                according to the docs you must define _WIN32_WINNT to 0x0600 or higher

                                I have used #define _WIN32_WINNT_WIN10 0x0A00 // Windows 10

                                I still would suggest you to simply use QtNetwork for this instead some low-level api calls.

                                What is the alternative of inet_pton in QtNetwork?

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

                                  @Imran-Hassan said in inet_pton 443: error: 'inet_pton' was not declared in this scope:

                                  I have used #define _WIN32_WINNT_WIN10 0x0A00 // Windows 10

                                  And what should this help? Please read my post

                                  What is the alternative of inet_pton in QtNetwork?

                                  "192.168.6.166" is a host address... https://doc.qt.io/qt-5/qhostaddress.html

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

                                  I 1 Reply Last reply
                                  3
                                  • Christian EhrlicherC Christian Ehrlicher

                                    @Imran-Hassan said in inet_pton 443: error: 'inet_pton' was not declared in this scope:

                                    I have used #define _WIN32_WINNT_WIN10 0x0A00 // Windows 10

                                    And what should this help? Please read my post

                                    What is the alternative of inet_pton in QtNetwork?

                                    "192.168.6.166" is a host address... https://doc.qt.io/qt-5/qhostaddress.html

                                    I Offline
                                    I Offline
                                    Imran Hassan
                                    wrote on last edited by
                                    #17

                                    @Christian-Ehrlicher Thanks dear. I will use this

                                    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