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. Send a request to an IP address
Forum Updated to NodeBB v4.3 + New Features

Send a request to an IP address

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 4 Posters 715 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.
  • R Raphawel

    **The objective of this program is to open a relay on an object connected to the network. I made all simple, I created a button that will send a request to the IP address 192.168.1.220 with "http://192.168.1.200/hidden.htm?M0:O1=ON" to open this relay.

    I have not yet seen if it works because I have a lot of errors, do you know why? And also do you think the program is right?**

    **My .h:**
    
    #ifndef REQUESTMANAGER_H
    #define REQUESTMANAGER_H
    
    #include <QMainWindow>
    #include <QtNetwork/QNetworkAccessManager>
    #include <QtNetwork/QNetworkRequest>
    #include <QtNetwork/QNetworkReply>
    #include <QtNetwork/QAuthenticator>
    #include <QPushButton>
    
    namespace Ui {
    class RequestManager;
    }
    
    class RequestManager : public QMainWindow
    {
        Q_OBJECT
    
    public:
        explicit RequestManager(QWidget *parent = 0);
        ~RequestManager();
    
    
    
    private slots:
        void on_sendButton_clicked();
        void handleResponse(QNetworkReply *reply);
        void sendRequest();
    
    private:
        Ui::RequestManager *ui;
        QNetworkAccessManager m_manager;
        QPushButton *m_button;
    };
    
    #endif // REQUESTMANAGER_H
    
    **My .cpp :** 
    #include "requestmanager.h"
    #include "ui_requestmanager.h"
    
    #include <QTextStream>
    #include <QByteArray>
    #include <QtNetwork/QNetworkAccessManager>
    #include <QtNetwork/QNetworkRequest>
    #include <QtNetwork/QNetworkReply>
    #include <QUrl>
    #include <QPushButton>
    
    RequestManager::RequestManager(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::RequestManager)
    {
        ui->setupUi(this);
    
        m_button = new QPushButton("Close Relay", this);
    
        //Appuie sur bouton pour envoyer la requête
        connect(m_button, &QPushButton::clicked, this, &RequestManager::on_sendButton_clicked);
    }
    
    RequestManager::~RequestManager()
    {
        delete ui;
    }
    
    void RequestManager::sendRequest()
    {
        QNetworkRequest request(QUrl("http://192.168.1.200/hidden.htm?M0:O1=ON"));
        QNetworkReply *reply = m_manager.get(request);
        connect(reply, &QNetworkReply::finished, this, &RequestManager::handleResponse);
    
    }
    
    void RequestManager::handleResponse(QNetworkReply *reply)
    {
        if (reply->error() != QNetworkReply::NoError) {
                // Handle error
      } else {
                // Process response data
            }
    
            reply->deleteLater();
    }
    
    
    void RequestManager::on_sendButton_clicked()
    {
        sendRequest();
    }
    

    My interface:
    4a4a22a2-af30-4475-b100-f24a2ae0e7af-image.png

    My errors:

    C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtGui\qwindowdefs.h:37: In file included from C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include/QtGui/qwindowdefs.h:37:0,

    C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets\qwidget.h:37: from C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include/QtWidgets/qwidget.h:37,

    C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets\qmainwindow.h:37: from C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets/qmainwindow.h:37,

    C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets\QMainWindow:1: from C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets/QMainWindow:1,

    C:\Users\46053500\Documents\Envoi_requete\Envoi_requete\requestmanager.h:4: from ..\Envoi_requete\requestmanager.h:4,

    C:\Users\46053500\Documents\Envoi_requete\Envoi_requete\requestmanager.cpp:1: from ..\Envoi_requete\requestmanager.cpp:1:

    C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtCore\qobject.h:-1: In instantiation of 'static QMetaObject::Connection QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, const typename QtPrivate::FunctionPointer<Func2>::Object*, Func2, Qt::ConnectionType) [with Func1 = void (QNetworkReply::)(); Func2 = void (RequestManager::)(QNetworkReply*); typename QtPrivate::FunctionPointer<Func>::Object = QNetworkReply; typename QtPrivate::FunctionPointer<Func2>::Object = RequestManager]':

    C:\Users\46053500\Documents\Envoi_requete\Envoi_requete\requestmanager.cpp:33: required from here

    C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtCore\qglobal.h:729: erreur : static assertion failed: The slot requires more arguments than the signal provides.
    #define Q_STATIC_ASSERT_X(Condition, Message) static_assert(bool(Condition), Message)
    ^

    C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtCore\qobject.h:224: in expansion of macro 'Q_STATIC_ASSERT_X'
    Q_STATIC_ASSERT_X(int(SignalType::ArgumentCount) >= int(SlotType::ArgumentCount),
    ^

    C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtCore\qglobal.h:729: erreur : static assertion failed: Signal and slot arguments are not compatible.
    #define Q_STATIC_ASSERT_X(Condition, Message) static_assert(bool(Condition), Message)

    C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtCore\qobject.h:226: in expansion of macro 'Q_STATIC_ASSERT_X'
    Q_STATIC_ASSERT_X((QtPrivate::CheckCompatibleArguments<typename SignalType::Arguments, typename SlotType::Arguments>::value),
    ^

    C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtCore\qobjectdefs.h:43: In file included from C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include/QtCore/qobjectdefs.h:43:0,

    C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtGui\qwindowdefs.h:38: from C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include/QtGui/qwindowdefs.h:38,

    C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets\qwidget.h:37: from C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include/QtWidgets/qwidget.h:37,

    C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets\qmainwindow.h:37: from C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets/qmainwindow.h:37,

    C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets\QMainWindow:1: from C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets/QMainWindow:1,

    C:\Users\46053500\Documents\Envoi_requete\Envoi_requete\requestmanager.h:4: from ..\Envoi_requete\requestmanager.h:4,

    C:\Users\46053500\Documents\Envoi_requete\Envoi_requete\requestmanager.cpp:1: from ..\Envoi_requete\requestmanager.cpp:1:

    C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtCore\qobjectdefs_impl.h:-1: In instantiation of 'struct QtPrivate::List_Left<QtPrivate::List<>, 1>':

    C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtCore\qobject.h:239: required from 'static QMetaObject::Connection QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, const typename QtPrivate::FunctionPointer<Func2>::Object*, Func2, Qt::ConnectionType) [with Func1 = void (QNetworkReply::)(); Func2 = void (RequestManager::)(QNetworkReply*); typename QtPrivate::FunctionPointer<Func>::Object = QNetworkReply; typename QtPrivate::FunctionPointer<Func2>::Object = RequestManager]'

    C:\Users\46053500\Documents\Envoi_requete\Envoi_requete\requestmanager.cpp:33: required from here

    C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtCore\qobjectdefs_impl.h:73: erreur : no type named 'Car' in 'struct QtPrivate::List<>'
    typedef typename List_Append<List<typename L::Car>,typename List_Left<typename L::Cdr, N - 1>::Value>::Value Value;
    ^

    C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets\qwidget.h:38: In file included from C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include/QtWidgets/qwidget.h:38:0,

    C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets\qmainwindow.h:37: from C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets/qmainwindow.h:37,

    C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets\QMainWindow:1: from C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets/QMainWindow:1,

    C:\Users\46053500\Documents\Envoi_requete\Envoi_requete\requestmanager.h:4: from ..\Envoi_requete\requestmanager.h:4,

    C:\Users\46053500\Documents\Envoi_requete\Envoi_requete\requestmanager.cpp:1: from ..\Envoi_requete\requestmanager.cpp:1:

    C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtCore\qobject.h:-1: In static member function 'static QMetaObject::Connection QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, const typename QtPrivate::FunctionPointer<Func2>::Object*, Func2, Qt::ConnectionType) [with Func1 = void (QNetworkReply::)(); Func2 = void (RequestManager::)(QNetworkReply*); typename QtPrivate::FunctionPointer<Func>::Object = QNetworkReply; typename QtPrivate::FunctionPointer<Func2>::Object = RequestManager]':

    C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtCore\qobject.h:240: avertissement : control reaches end of non-void function [-Wreturn-type]
    }
    ^

    Thanks for your help!

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

    @Raphawel Please post source code as text!
    If you have many errors then please post the first one (again: please post it as text).

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

    R 1 Reply Last reply
    2
    • jsulmJ jsulm

      @Raphawel Please post source code as text!
      If you have many errors then please post the first one (again: please post it as text).

      R Offline
      R Offline
      Raphawel
      wrote on last edited by
      #3

      @jsulm said in Send a request to an IP address:

      @Raphawel Please post source code as text!
      If you have many errors then please post the first one (again: please post it as text).

      It's done, excuse me. But for the mistakes I prefer to leave the picture instead of writing them, even if I write some. PS: I will change if it does not suit you

      jsulmJ 1 Reply Last reply
      0
      • R Raphawel

        @jsulm said in Send a request to an IP address:

        @Raphawel Please post source code as text!
        If you have many errors then please post the first one (again: please post it as text).

        It's done, excuse me. But for the mistakes I prefer to leave the picture instead of writing them, even if I write some. PS: I will change if it does not suit you

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

        @Raphawel said in Send a request to an IP address:

        I prefer to leave the picture instead of writing them

        No need to write: you can simply copy/paste...

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

        R 1 Reply Last reply
        0
        • jsulmJ jsulm

          @Raphawel said in Send a request to an IP address:

          I prefer to leave the picture instead of writing them

          No need to write: you can simply copy/paste...

          R Offline
          R Offline
          Raphawel
          wrote on last edited by
          #5

          @jsulm It's done

          JonBJ 1 Reply Last reply
          0
          • R Raphawel

            @jsulm It's done

            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by
            #6

            @Raphawel
            I cannot spot what the issue is. But do you really have to use such an old version of Qt as 5.6.3, in case that is relevant? It won't do you any favors in the long run....

            R 1 Reply Last reply
            0
            • JonBJ JonB

              @Raphawel
              I cannot spot what the issue is. But do you really have to use such an old version of Qt as 5.6.3, in case that is relevant? It won't do you any favors in the long run....

              R Offline
              R Offline
              Raphawel
              wrote on last edited by
              #7

              @JonB said in Send a request to an IP address:

              @Raphawel
              I cannot spot what the issue is. But do you really have to use such an old version of Qt as 5.6.3, in case that is relevant? It won't do you any favors in the long run....

              Thank you for your answer. Yes, I have to use version 5.6.3 to be able to use the application under 32 bit.

              1 Reply Last reply
              0
              • R Raphawel

                **The objective of this program is to open a relay on an object connected to the network. I made all simple, I created a button that will send a request to the IP address 192.168.1.220 with "http://192.168.1.200/hidden.htm?M0:O1=ON" to open this relay.

                I have not yet seen if it works because I have a lot of errors, do you know why? And also do you think the program is right?**

                **My .h:**
                
                #ifndef REQUESTMANAGER_H
                #define REQUESTMANAGER_H
                
                #include <QMainWindow>
                #include <QtNetwork/QNetworkAccessManager>
                #include <QtNetwork/QNetworkRequest>
                #include <QtNetwork/QNetworkReply>
                #include <QtNetwork/QAuthenticator>
                #include <QPushButton>
                
                namespace Ui {
                class RequestManager;
                }
                
                class RequestManager : public QMainWindow
                {
                    Q_OBJECT
                
                public:
                    explicit RequestManager(QWidget *parent = 0);
                    ~RequestManager();
                
                
                
                private slots:
                    void on_sendButton_clicked();
                    void handleResponse(QNetworkReply *reply);
                    void sendRequest();
                
                private:
                    Ui::RequestManager *ui;
                    QNetworkAccessManager m_manager;
                    QPushButton *m_button;
                };
                
                #endif // REQUESTMANAGER_H
                
                **My .cpp :** 
                #include "requestmanager.h"
                #include "ui_requestmanager.h"
                
                #include <QTextStream>
                #include <QByteArray>
                #include <QtNetwork/QNetworkAccessManager>
                #include <QtNetwork/QNetworkRequest>
                #include <QtNetwork/QNetworkReply>
                #include <QUrl>
                #include <QPushButton>
                
                RequestManager::RequestManager(QWidget *parent) :
                    QMainWindow(parent),
                    ui(new Ui::RequestManager)
                {
                    ui->setupUi(this);
                
                    m_button = new QPushButton("Close Relay", this);
                
                    //Appuie sur bouton pour envoyer la requête
                    connect(m_button, &QPushButton::clicked, this, &RequestManager::on_sendButton_clicked);
                }
                
                RequestManager::~RequestManager()
                {
                    delete ui;
                }
                
                void RequestManager::sendRequest()
                {
                    QNetworkRequest request(QUrl("http://192.168.1.200/hidden.htm?M0:O1=ON"));
                    QNetworkReply *reply = m_manager.get(request);
                    connect(reply, &QNetworkReply::finished, this, &RequestManager::handleResponse);
                
                }
                
                void RequestManager::handleResponse(QNetworkReply *reply)
                {
                    if (reply->error() != QNetworkReply::NoError) {
                            // Handle error
                  } else {
                            // Process response data
                        }
                
                        reply->deleteLater();
                }
                
                
                void RequestManager::on_sendButton_clicked()
                {
                    sendRequest();
                }
                

                My interface:
                4a4a22a2-af30-4475-b100-f24a2ae0e7af-image.png

                My errors:

                C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtGui\qwindowdefs.h:37: In file included from C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include/QtGui/qwindowdefs.h:37:0,

                C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets\qwidget.h:37: from C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include/QtWidgets/qwidget.h:37,

                C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets\qmainwindow.h:37: from C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets/qmainwindow.h:37,

                C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets\QMainWindow:1: from C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets/QMainWindow:1,

                C:\Users\46053500\Documents\Envoi_requete\Envoi_requete\requestmanager.h:4: from ..\Envoi_requete\requestmanager.h:4,

                C:\Users\46053500\Documents\Envoi_requete\Envoi_requete\requestmanager.cpp:1: from ..\Envoi_requete\requestmanager.cpp:1:

                C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtCore\qobject.h:-1: In instantiation of 'static QMetaObject::Connection QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, const typename QtPrivate::FunctionPointer<Func2>::Object*, Func2, Qt::ConnectionType) [with Func1 = void (QNetworkReply::)(); Func2 = void (RequestManager::)(QNetworkReply*); typename QtPrivate::FunctionPointer<Func>::Object = QNetworkReply; typename QtPrivate::FunctionPointer<Func2>::Object = RequestManager]':

                C:\Users\46053500\Documents\Envoi_requete\Envoi_requete\requestmanager.cpp:33: required from here

                C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtCore\qglobal.h:729: erreur : static assertion failed: The slot requires more arguments than the signal provides.
                #define Q_STATIC_ASSERT_X(Condition, Message) static_assert(bool(Condition), Message)
                ^

                C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtCore\qobject.h:224: in expansion of macro 'Q_STATIC_ASSERT_X'
                Q_STATIC_ASSERT_X(int(SignalType::ArgumentCount) >= int(SlotType::ArgumentCount),
                ^

                C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtCore\qglobal.h:729: erreur : static assertion failed: Signal and slot arguments are not compatible.
                #define Q_STATIC_ASSERT_X(Condition, Message) static_assert(bool(Condition), Message)

                C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtCore\qobject.h:226: in expansion of macro 'Q_STATIC_ASSERT_X'
                Q_STATIC_ASSERT_X((QtPrivate::CheckCompatibleArguments<typename SignalType::Arguments, typename SlotType::Arguments>::value),
                ^

                C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtCore\qobjectdefs.h:43: In file included from C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include/QtCore/qobjectdefs.h:43:0,

                C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtGui\qwindowdefs.h:38: from C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include/QtGui/qwindowdefs.h:38,

                C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets\qwidget.h:37: from C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include/QtWidgets/qwidget.h:37,

                C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets\qmainwindow.h:37: from C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets/qmainwindow.h:37,

                C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets\QMainWindow:1: from C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets/QMainWindow:1,

                C:\Users\46053500\Documents\Envoi_requete\Envoi_requete\requestmanager.h:4: from ..\Envoi_requete\requestmanager.h:4,

                C:\Users\46053500\Documents\Envoi_requete\Envoi_requete\requestmanager.cpp:1: from ..\Envoi_requete\requestmanager.cpp:1:

                C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtCore\qobjectdefs_impl.h:-1: In instantiation of 'struct QtPrivate::List_Left<QtPrivate::List<>, 1>':

                C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtCore\qobject.h:239: required from 'static QMetaObject::Connection QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, const typename QtPrivate::FunctionPointer<Func2>::Object*, Func2, Qt::ConnectionType) [with Func1 = void (QNetworkReply::)(); Func2 = void (RequestManager::)(QNetworkReply*); typename QtPrivate::FunctionPointer<Func>::Object = QNetworkReply; typename QtPrivate::FunctionPointer<Func2>::Object = RequestManager]'

                C:\Users\46053500\Documents\Envoi_requete\Envoi_requete\requestmanager.cpp:33: required from here

                C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtCore\qobjectdefs_impl.h:73: erreur : no type named 'Car' in 'struct QtPrivate::List<>'
                typedef typename List_Append<List<typename L::Car>,typename List_Left<typename L::Cdr, N - 1>::Value>::Value Value;
                ^

                C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets\qwidget.h:38: In file included from C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include/QtWidgets/qwidget.h:38:0,

                C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets\qmainwindow.h:37: from C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets/qmainwindow.h:37,

                C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets\QMainWindow:1: from C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets/QMainWindow:1,

                C:\Users\46053500\Documents\Envoi_requete\Envoi_requete\requestmanager.h:4: from ..\Envoi_requete\requestmanager.h:4,

                C:\Users\46053500\Documents\Envoi_requete\Envoi_requete\requestmanager.cpp:1: from ..\Envoi_requete\requestmanager.cpp:1:

                C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtCore\qobject.h:-1: In static member function 'static QMetaObject::Connection QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, const typename QtPrivate::FunctionPointer<Func2>::Object*, Func2, Qt::ConnectionType) [with Func1 = void (QNetworkReply::)(); Func2 = void (RequestManager::)(QNetworkReply*); typename QtPrivate::FunctionPointer<Func>::Object = QNetworkReply; typename QtPrivate::FunctionPointer<Func2>::Object = RequestManager]':

                C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtCore\qobject.h:240: avertissement : control reaches end of non-void function [-Wreturn-type]
                }
                ^

                Thanks for your help!

                J.HilkJ Online
                J.HilkJ Online
                J.Hilk
                Moderators
                wrote on last edited by
                #8

                @Raphawel said in Send a request to an IP address:

                #include <QtNetwork/QNetworkAccessManager>

                this is an usually include pattern. Did you correctly add the network module to your project ?

                cmake:

                find_package(Qt6 REQUIRED COMPONENTS Network) 
                target_link_libraries(mytarget PRIVATE Qt6::Network)
                

                qmake:

                QT += network
                

                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                R 1 Reply Last reply
                0
                • J.HilkJ J.Hilk

                  @Raphawel said in Send a request to an IP address:

                  #include <QtNetwork/QNetworkAccessManager>

                  this is an usually include pattern. Did you correctly add the network module to your project ?

                  cmake:

                  find_package(Qt6 REQUIRED COMPONENTS Network) 
                  target_link_libraries(mytarget PRIVATE Qt6::Network)
                  

                  qmake:

                  QT += network
                  
                  R Offline
                  R Offline
                  Raphawel
                  wrote on last edited by
                  #9

                  @J-Hilk Thanks for your answer

                  #-------------------------------------------------
                  #
                  # Project created by QtCreator 2023-02-08T14:04:54
                  #
                  #-------------------------------------------------
                  
                  QT       += core gui
                  QT += network
                  
                  greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
                  
                  TARGET = Envoi_requete
                  TEMPLATE = app
                  
                  
                  SOURCES += main.cpp\
                          requestmanager.cpp
                  
                  HEADERS  += requestmanager.h
                  
                  FORMS    += requestmanager.ui
                  

                  Yes I have

                  JonBJ 1 Reply Last reply
                  0
                  • R Raphawel

                    @J-Hilk Thanks for your answer

                    #-------------------------------------------------
                    #
                    # Project created by QtCreator 2023-02-08T14:04:54
                    #
                    #-------------------------------------------------
                    
                    QT       += core gui
                    QT += network
                    
                    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
                    
                    TARGET = Envoi_requete
                    TEMPLATE = app
                    
                    
                    SOURCES += main.cpp\
                            requestmanager.cpp
                    
                    HEADERS  += requestmanager.h
                    
                    FORMS    += requestmanager.ui
                    

                    Yes I have

                    JonBJ Online
                    JonBJ Online
                    JonB
                    wrote on last edited by JonB
                    #10

                    @Raphawel
                    Just to check: have you deleted all the files in the build output directory, and re-run qmake and compilation? You need to make sure everything is "clean" before you continue.

                    R 1 Reply Last reply
                    0
                    • R Raphawel

                      **The objective of this program is to open a relay on an object connected to the network. I made all simple, I created a button that will send a request to the IP address 192.168.1.220 with "http://192.168.1.200/hidden.htm?M0:O1=ON" to open this relay.

                      I have not yet seen if it works because I have a lot of errors, do you know why? And also do you think the program is right?**

                      **My .h:**
                      
                      #ifndef REQUESTMANAGER_H
                      #define REQUESTMANAGER_H
                      
                      #include <QMainWindow>
                      #include <QtNetwork/QNetworkAccessManager>
                      #include <QtNetwork/QNetworkRequest>
                      #include <QtNetwork/QNetworkReply>
                      #include <QtNetwork/QAuthenticator>
                      #include <QPushButton>
                      
                      namespace Ui {
                      class RequestManager;
                      }
                      
                      class RequestManager : public QMainWindow
                      {
                          Q_OBJECT
                      
                      public:
                          explicit RequestManager(QWidget *parent = 0);
                          ~RequestManager();
                      
                      
                      
                      private slots:
                          void on_sendButton_clicked();
                          void handleResponse(QNetworkReply *reply);
                          void sendRequest();
                      
                      private:
                          Ui::RequestManager *ui;
                          QNetworkAccessManager m_manager;
                          QPushButton *m_button;
                      };
                      
                      #endif // REQUESTMANAGER_H
                      
                      **My .cpp :** 
                      #include "requestmanager.h"
                      #include "ui_requestmanager.h"
                      
                      #include <QTextStream>
                      #include <QByteArray>
                      #include <QtNetwork/QNetworkAccessManager>
                      #include <QtNetwork/QNetworkRequest>
                      #include <QtNetwork/QNetworkReply>
                      #include <QUrl>
                      #include <QPushButton>
                      
                      RequestManager::RequestManager(QWidget *parent) :
                          QMainWindow(parent),
                          ui(new Ui::RequestManager)
                      {
                          ui->setupUi(this);
                      
                          m_button = new QPushButton("Close Relay", this);
                      
                          //Appuie sur bouton pour envoyer la requête
                          connect(m_button, &QPushButton::clicked, this, &RequestManager::on_sendButton_clicked);
                      }
                      
                      RequestManager::~RequestManager()
                      {
                          delete ui;
                      }
                      
                      void RequestManager::sendRequest()
                      {
                          QNetworkRequest request(QUrl("http://192.168.1.200/hidden.htm?M0:O1=ON"));
                          QNetworkReply *reply = m_manager.get(request);
                          connect(reply, &QNetworkReply::finished, this, &RequestManager::handleResponse);
                      
                      }
                      
                      void RequestManager::handleResponse(QNetworkReply *reply)
                      {
                          if (reply->error() != QNetworkReply::NoError) {
                                  // Handle error
                        } else {
                                  // Process response data
                              }
                      
                              reply->deleteLater();
                      }
                      
                      
                      void RequestManager::on_sendButton_clicked()
                      {
                          sendRequest();
                      }
                      

                      My interface:
                      4a4a22a2-af30-4475-b100-f24a2ae0e7af-image.png

                      My errors:

                      C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtGui\qwindowdefs.h:37: In file included from C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include/QtGui/qwindowdefs.h:37:0,

                      C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets\qwidget.h:37: from C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include/QtWidgets/qwidget.h:37,

                      C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets\qmainwindow.h:37: from C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets/qmainwindow.h:37,

                      C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets\QMainWindow:1: from C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets/QMainWindow:1,

                      C:\Users\46053500\Documents\Envoi_requete\Envoi_requete\requestmanager.h:4: from ..\Envoi_requete\requestmanager.h:4,

                      C:\Users\46053500\Documents\Envoi_requete\Envoi_requete\requestmanager.cpp:1: from ..\Envoi_requete\requestmanager.cpp:1:

                      C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtCore\qobject.h:-1: In instantiation of 'static QMetaObject::Connection QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, const typename QtPrivate::FunctionPointer<Func2>::Object*, Func2, Qt::ConnectionType) [with Func1 = void (QNetworkReply::)(); Func2 = void (RequestManager::)(QNetworkReply*); typename QtPrivate::FunctionPointer<Func>::Object = QNetworkReply; typename QtPrivate::FunctionPointer<Func2>::Object = RequestManager]':

                      C:\Users\46053500\Documents\Envoi_requete\Envoi_requete\requestmanager.cpp:33: required from here

                      C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtCore\qglobal.h:729: erreur : static assertion failed: The slot requires more arguments than the signal provides.
                      #define Q_STATIC_ASSERT_X(Condition, Message) static_assert(bool(Condition), Message)
                      ^

                      C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtCore\qobject.h:224: in expansion of macro 'Q_STATIC_ASSERT_X'
                      Q_STATIC_ASSERT_X(int(SignalType::ArgumentCount) >= int(SlotType::ArgumentCount),
                      ^

                      C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtCore\qglobal.h:729: erreur : static assertion failed: Signal and slot arguments are not compatible.
                      #define Q_STATIC_ASSERT_X(Condition, Message) static_assert(bool(Condition), Message)

                      C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtCore\qobject.h:226: in expansion of macro 'Q_STATIC_ASSERT_X'
                      Q_STATIC_ASSERT_X((QtPrivate::CheckCompatibleArguments<typename SignalType::Arguments, typename SlotType::Arguments>::value),
                      ^

                      C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtCore\qobjectdefs.h:43: In file included from C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include/QtCore/qobjectdefs.h:43:0,

                      C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtGui\qwindowdefs.h:38: from C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include/QtGui/qwindowdefs.h:38,

                      C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets\qwidget.h:37: from C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include/QtWidgets/qwidget.h:37,

                      C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets\qmainwindow.h:37: from C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets/qmainwindow.h:37,

                      C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets\QMainWindow:1: from C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets/QMainWindow:1,

                      C:\Users\46053500\Documents\Envoi_requete\Envoi_requete\requestmanager.h:4: from ..\Envoi_requete\requestmanager.h:4,

                      C:\Users\46053500\Documents\Envoi_requete\Envoi_requete\requestmanager.cpp:1: from ..\Envoi_requete\requestmanager.cpp:1:

                      C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtCore\qobjectdefs_impl.h:-1: In instantiation of 'struct QtPrivate::List_Left<QtPrivate::List<>, 1>':

                      C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtCore\qobject.h:239: required from 'static QMetaObject::Connection QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, const typename QtPrivate::FunctionPointer<Func2>::Object*, Func2, Qt::ConnectionType) [with Func1 = void (QNetworkReply::)(); Func2 = void (RequestManager::)(QNetworkReply*); typename QtPrivate::FunctionPointer<Func>::Object = QNetworkReply; typename QtPrivate::FunctionPointer<Func2>::Object = RequestManager]'

                      C:\Users\46053500\Documents\Envoi_requete\Envoi_requete\requestmanager.cpp:33: required from here

                      C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtCore\qobjectdefs_impl.h:73: erreur : no type named 'Car' in 'struct QtPrivate::List<>'
                      typedef typename List_Append<List<typename L::Car>,typename List_Left<typename L::Cdr, N - 1>::Value>::Value Value;
                      ^

                      C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets\qwidget.h:38: In file included from C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include/QtWidgets/qwidget.h:38:0,

                      C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets\qmainwindow.h:37: from C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets/qmainwindow.h:37,

                      C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets\QMainWindow:1: from C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtWidgets/QMainWindow:1,

                      C:\Users\46053500\Documents\Envoi_requete\Envoi_requete\requestmanager.h:4: from ..\Envoi_requete\requestmanager.h:4,

                      C:\Users\46053500\Documents\Envoi_requete\Envoi_requete\requestmanager.cpp:1: from ..\Envoi_requete\requestmanager.cpp:1:

                      C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtCore\qobject.h:-1: In static member function 'static QMetaObject::Connection QObject::connect(const typename QtPrivate::FunctionPointer<Func>::Object*, Func1, const typename QtPrivate::FunctionPointer<Func2>::Object*, Func2, Qt::ConnectionType) [with Func1 = void (QNetworkReply::)(); Func2 = void (RequestManager::)(QNetworkReply*); typename QtPrivate::FunctionPointer<Func>::Object = QNetworkReply; typename QtPrivate::FunctionPointer<Func2>::Object = RequestManager]':

                      C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtCore\qobject.h:240: avertissement : control reaches end of non-void function [-Wreturn-type]
                      }
                      ^

                      Thanks for your help!

                      JonBJ Online
                      JonBJ Online
                      JonB
                      wrote on last edited by JonB
                      #11

                      @Raphawel said in Send a request to an IP address:

                      C:\QT_5.6.3_MinGW\5.6.3\mingw49_32\include\QtCore\qglobal.h:729: erreur : static assertion failed: The slot requires more arguments than the signal provides.
                      #define Q_STATIC_ASSERT_X(Condition, Message) static_assert(bool(Condition), Message)

                      connect(reply, &QNetworkReply::finished, this, &RequestManager::handleResponse);

                      void RequestManager::handleResponse(QNetworkReply *reply)

                      void QNetworkReply::finished() signal passes no parameters. Your handleResponse(QNetworkReply *reply) slot requires one. Hence the error message (see the bit I have bolded).

                      1 Reply Last reply
                      2
                      • JonBJ JonB

                        @Raphawel
                        Just to check: have you deleted all the files in the build output directory, and re-run qmake and compilation? You need to make sure everything is "clean" before you continue.

                        R Offline
                        R Offline
                        Raphawel
                        wrote on last edited by Raphawel
                        #12

                        @JonB That is to say, delete all the files from here :

                        cc1e8b93-a0c3-4a40-8b7c-b93550c0a9ab-image.png

                        or here :

                        2fbfd4b7-039d-43b6-baa7-425600623857-image.png

                        And to be sure re-launch qmake it is this (at the bottom left):

                        ff10f084-30e0-4889-926e-b8d241f891b4-image.png

                        JonBJ 1 Reply Last reply
                        0
                        • R Raphawel

                          @JonB That is to say, delete all the files from here :

                          cc1e8b93-a0c3-4a40-8b7c-b93550c0a9ab-image.png

                          or here :

                          2fbfd4b7-039d-43b6-baa7-425600623857-image.png

                          And to be sure re-launch qmake it is this (at the bottom left):

                          ff10f084-30e0-4889-926e-b8d241f891b4-image.png

                          JonBJ Online
                          JonBJ Online
                          JonB
                          wrote on last edited by
                          #13

                          @Raphawel
                          No, not source files! If you don't know what your build output folder is you'd better not touch anything! :)

                          In any case you may not need this. See my later post when I spotted your bad connect() signal/slot call, that may be all you need to fix.

                          R 1 Reply Last reply
                          1
                          • JonBJ JonB

                            @Raphawel
                            No, not source files! If you don't know what your build output folder is you'd better not touch anything! :)

                            In any case you may not need this. See my later post when I spotted your bad connect() signal/slot call, that may be all you need to fix.

                            R Offline
                            R Offline
                            Raphawel
                            wrote on last edited by Raphawel
                            #14

                            @JonB Ok thanks for your help but I managed to get my relay opened. In the code I modified this part by changing :
                            My .h:

                            #ifndef REQUESTMANAGER_H
                            #define REQUESTMANAGER_H
                            
                            #include <QMainWindow>
                            #include <QtNetwork/QNetworkAccessManager>
                            #include <QtNetwork/QNetworkRequest>
                            #include <QtNetwork/QNetworkReply>
                            #include <QtNetwork/QAuthenticator>
                            #include <QPushButton>
                            
                            namespace Ui {
                            class RequestManager;
                            }
                            
                            class RequestManager : public QMainWindow
                            {
                                Q_OBJECT
                            
                            public:
                                explicit RequestManager(QWidget *parent = 0);
                                ~RequestManager();
                            
                            
                            
                            private slots:
                                void on_sendButton_clicked();
                                void handleResponse(); // changing handleResponse(QNetworkReply *reply);
                                void sendRequest();
                            
                            private:
                                Ui::RequestManager *ui;
                                QNetworkAccessManager m_manager;
                                QPushButton *m_button;
                                QNetworkReply *m_reply; //add
                            };
                            
                            #endif // REQUESTMANAGER_H
                            

                            My .cpp :

                            #include "requestmanager.h"
                            #include "ui_requestmanager.h"
                            
                            #include <QCoreApplication>
                            #include <QObject>
                            #include <QTextStream>
                            #include <QByteArray>
                            #include <QtNetwork/QNetworkAccessManager>
                            #include <QtNetwork/QNetworkRequest>
                            #include <QtNetwork/QNetworkReply>
                            #include <QUrl>
                            #include <QPushButton>
                            
                            RequestManager::RequestManager(QWidget *parent) :
                                QMainWindow(parent),
                                ui(new Ui::RequestManager)
                            {
                                ui->setupUi(this);
                            
                                m_button = new QPushButton("Close Relay", this);
                            
                                //Appuie sur bouton pour envoyer la requête
                                connect(m_button, &QPushButton::clicked, this, &RequestManager::on_sendButton_clicked);
                            
                            }
                            
                            RequestManager::~RequestManager()
                            {
                                delete ui;
                            }
                            
                            void RequestManager::sendRequest()
                            {
                                QNetworkRequest request(QUrl("http://192.168.1.220/hidden.htm?M0:O1=ON"));
                                m_reply = m_manager.get(request);
                                connect(m_reply, &QNetworkReply::finished, this, &RequestManager::handleResponse);
                            
                            }
                            
                            void RequestManager::handleResponse()
                            {
                                QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender()); //add
                                if (reply->error() != QNetworkReply::NoError) {
                                        // Handle error
                                    } else {
                                        // Process response data
                                    }
                            
                                    reply->deleteLater();
                                    m_reply = nullptr; //add
                            }
                            
                            
                            void RequestManager::on_sendButton_clicked()
                            {
                                sendRequest();
                            }
                            

                            And thanks to these changes no more errors, there was an error in the slots :)

                            1 Reply Last reply
                            1
                            • R Raphawel has marked this topic as solved on

                            • Login

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