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. Error: QIODevice::read (QDisabledNetworkReply): device not open on https request
Qt 6.11 is out! See what's new in the release blog

Error: QIODevice::read (QDisabledNetworkReply): device not open on https request

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 3 Posters 6.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.
  • NabiN Offline
    NabiN Offline
    Nabi
    wrote on last edited by
    #2

    Actualy it works on localhost, but not to others

    aha_1980A 1 Reply Last reply
    0
    • NabiN Nabi

      Actualy it works on localhost, but not to others

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #3

      Hi @Nabi,

      You are creating the network request on the stack here:

      QNetworkRequest qtr(QUrl("https://host"));

      so it will be destroyed when the function MainWindow::on_pushButton_clicked() finishes.

      I guess you need to create a member variable for your network request and you should be fine.

      Regards

      Qt has to stay free or it will die.

      1 Reply Last reply
      2
      • NabiN Offline
        NabiN Offline
        Nabi
        wrote on last edited by
        #4

        Thanks for help!
        I made QNetworkRequest as member, but result: QIODevice::read(QDisabledNetworkReply): device not open

        aha_1980A 1 Reply Last reply
        0
        • NabiN Nabi

          Thanks for help!
          I made QNetworkRequest as member, but result: QIODevice::read(QDisabledNetworkReply): device not open

          aha_1980A Offline
          aha_1980A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on last edited by
          #5

          hi @Nabi,

          please show your code.

          Qt has to stay free or it will die.

          1 Reply Last reply
          0
          • NabiN Offline
            NabiN Offline
            Nabi
            wrote on last edited by
            #6

            Hi!
            It's interesting world, yesterday I tested everything, result same error, today I didn't change anything, run app and all right, it works:)))!
            This is my code:

            Header file:
            #include <QMainWindow>
            #include <QNetworkAccessManager>
            #include <QUrl>

            namespace Ui {
            class MainWindow;

            }

            class MainWindow : public QMainWindow
            {
            Q_OBJECT

            public:
            explicit MainWindow(QWidget *parent = 0);
            ~MainWindow();

            private slots:
            void on_pushButton_clicked();
            void request_finished();
            void error_occurred();

            private:
            Ui::MainWindow *ui;
            QUrl url;
            QNetworkRequest qtr;
            QNetworkAccessManager qnam;
            QNetworkReply *reply;
            };

            #endif // MAINWINDOW_H

            source file:

            #include "mainwindow.h"
            #include "ui_mainwindow.h"
            #include "QtNetwork"
            #include <QUrl>
            #include <QDebug>
            #include <QSslConfiguration>
            #include <QtCore/QVariant>

            MainWindow::MainWindow(QWidget *parent) :
            QMainWindow(parent),
            ui(new Ui::MainWindow)
            {
            ui->setupUi(this);
            }

            MainWindow::~MainWindow()
            {
            delete ui;
            }

            void MainWindow::on_pushButton_clicked()
            {

                QByteArray data = "login=admin&password=123";
                qtr.setUrl(QUrl("https://host"));
                qtr.setRawHeader("Accept","application/json");
                qtr.setRawHeader("Content-Type","application/x-www-form-urlencoded");
                qtr.setRawHeader("key,"value");
            
                QSslConfiguration config = QSslConfiguration::defaultConfiguration();
                config.setProtocol(QSsl::TlsV1_2);
                qtr.setSslConfiguration(config);
                reply = qnam.post(qtr,data);
                connect(reply, &QNetworkReply::finished, this, &MainWindow::request_finished);
                connect(reply, &QNetworkReply::sslErrors, this, &MainWindow::error_occurred);
            

            }

            void MainWindow::request_finished() {
            qDebug() << "request finished!";
            QByteArray data = reply->readAll();
            qDebug() << data;
            QJsonDocument jsonDoc(QJsonDocument::fromJson(data));
            QJsonObject jsonObject = jsonDoc.object();
            QString token = jsonObject["key"].toString();
            if(token == "") {
            qDebug() << "Login password incorrect!";
            } else {
            qDebug() << "All right";
            }
            reply->deleteLater();
            }

            void MainWindow::error_occurred() {
            qDebug() << "error occurred";
            }

            If something wrong, please notice me!

            jsulmJ 1 Reply Last reply
            0
            • NabiN Nabi

              Hi!
              It's interesting world, yesterday I tested everything, result same error, today I didn't change anything, run app and all right, it works:)))!
              This is my code:

              Header file:
              #include <QMainWindow>
              #include <QNetworkAccessManager>
              #include <QUrl>

              namespace Ui {
              class MainWindow;

              }

              class MainWindow : public QMainWindow
              {
              Q_OBJECT

              public:
              explicit MainWindow(QWidget *parent = 0);
              ~MainWindow();

              private slots:
              void on_pushButton_clicked();
              void request_finished();
              void error_occurred();

              private:
              Ui::MainWindow *ui;
              QUrl url;
              QNetworkRequest qtr;
              QNetworkAccessManager qnam;
              QNetworkReply *reply;
              };

              #endif // MAINWINDOW_H

              source file:

              #include "mainwindow.h"
              #include "ui_mainwindow.h"
              #include "QtNetwork"
              #include <QUrl>
              #include <QDebug>
              #include <QSslConfiguration>
              #include <QtCore/QVariant>

              MainWindow::MainWindow(QWidget *parent) :
              QMainWindow(parent),
              ui(new Ui::MainWindow)
              {
              ui->setupUi(this);
              }

              MainWindow::~MainWindow()
              {
              delete ui;
              }

              void MainWindow::on_pushButton_clicked()
              {

                  QByteArray data = "login=admin&password=123";
                  qtr.setUrl(QUrl("https://host"));
                  qtr.setRawHeader("Accept","application/json");
                  qtr.setRawHeader("Content-Type","application/x-www-form-urlencoded");
                  qtr.setRawHeader("key,"value");
              
                  QSslConfiguration config = QSslConfiguration::defaultConfiguration();
                  config.setProtocol(QSsl::TlsV1_2);
                  qtr.setSslConfiguration(config);
                  reply = qnam.post(qtr,data);
                  connect(reply, &QNetworkReply::finished, this, &MainWindow::request_finished);
                  connect(reply, &QNetworkReply::sslErrors, this, &MainWindow::error_occurred);
              

              }

              void MainWindow::request_finished() {
              qDebug() << "request finished!";
              QByteArray data = reply->readAll();
              qDebug() << data;
              QJsonDocument jsonDoc(QJsonDocument::fromJson(data));
              QJsonObject jsonObject = jsonDoc.object();
              QString token = jsonObject["key"].toString();
              if(token == "") {
              qDebug() << "Login password incorrect!";
              } else {
              qDebug() << "All right";
              }
              reply->deleteLater();
              }

              void MainWindow::error_occurred() {
              qDebug() << "error occurred";
              }

              If something wrong, please notice me!

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

              @Nabi You should cinnect a slot to http://doc.qt.io/qt-5/qnetworkreply.html#error-1 as well to see whether you get any errors

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

              1 Reply Last reply
              2
              • NabiN Offline
                NabiN Offline
                Nabi
                wrote on last edited by
                #8

                Hi!
                @jsulm I got this error: "Network access is disabled."

                jsulmJ 1 Reply Last reply
                0
                • NabiN Nabi

                  Hi!
                  @jsulm I got this error: "Network access is disabled."

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

                  @Nabi Does the server actually support/allow these requests?

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

                  NabiN 1 Reply Last reply
                  0
                  • jsulmJ jsulm

                    @Nabi Does the server actually support/allow these requests?

                    NabiN Offline
                    NabiN Offline
                    Nabi
                    wrote on last edited by Nabi
                    #10

                    @jsulm Yes! First I tested this request on Postman, all right. My request can't get access on remote hosts, on localhost all right. Sometimes it works, it seems me OS blocks app, but i don't have any antivirus and windows firewall (brandmauer) off.

                    1 Reply Last reply
                    0
                    • NabiN Offline
                      NabiN Offline
                      Nabi
                      wrote on last edited by Nabi
                      #11

                      I didn't change anything and today it works, I think sometimes actually OS blocks my application. But how to get access forever, actually port 443 and 80 (http and https) always open.
                      I added this line code reply->deleteLater() to clear memory and I didn't send many requests, so OS should not block my application.
                      Why sometimes OS blocks my application?
                      I have installed OS Windows 8.1
                      I think or i have some bugs, or I didn't handle some important errors, or I didn't add some important lines code to get access

                      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