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. Getting SIGSEGV on "finished" signal from QNetwowkAccessManager
Forum Update on Monday, May 27th 2025

Getting SIGSEGV on "finished" signal from QNetwowkAccessManager

Scheduled Pinned Locked Moved General and Desktop
qnetworkaccessmqnetreply
13 Posts 2 Posters 4.8k 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.
  • F Offline
    F Offline
    Fernando
    wrote on last edited by
    #1

    Hi everyone,

    long time lurker, first time poster. :-)

    I'm using QT 5.4.1 under Windows7-64.

    I have a serious problem with QNetworkAccessManager: I got SIGSEGV when the "finished" signal fires, but only in Debug mode!! :-(

    My sample:

    mainwindow.h

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>
    #include <QNetworkAccessManager>
    #include <QNetworkReply>
    #include <QNetworkRequest>
    #include <QFile>
    #include <QDebug>

    #define TEST_URL "http://www.gnu.org/licenses/gpl-3.0.txt"

    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

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

    private:
    Ui::MainWindow *ui;

    QNetworkAccessManager* mpNetManager;
    
    void initializeNetwork();
    
    void testDownload();
    

    private slots:
    void downloadFinished(QNetworkReply*);
    };

    #endif // MAINWINDOW_H

    mainwindow.cpp

    #include "mainwindow.h"
    #include "ui_mainwindow.h"

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

    MainWindow::~MainWindow()
    {
    delete ui;
    mpNetManager->deleteLater();
    }

    void MainWindow::initializeNetwork()
    {
    mpNetManager = new QNetworkAccessManager;
    }

    void MainWindow::testDownload()
    {
    if (mpNetManager)
    {
    QNetworkRequest netRequest;
    QUrl downloadURL(TEST_URL);
    netRequest.setUrl(downloadURL);
    connect(mpNetManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(downloadFinished()));
    mpNetManager->get(netRequest);
    }
    }

    void MainWindow::downloadFinished (QNetworkReply* pNetReply)
    {
    if (pNetReply)
    {
    if(pNetReply->error())
    {
    qDebug() << "ERROR!";
    qDebug() << pNetReply->errorString();
    }
    else
    {
    QString qsDownloadPath = "downloaded.txt";
    QFile *pOutFile = new QFile(qsDownloadPath);
    if(pOutFile->open(QFile::WriteOnly))
    {
    pOutFile->write(pNetReply->readAll());
    pOutFile->flush();
    pOutFile->close();
    }
    delete pOutFile;
    qDebug() << "Download finished";
    qDebug() << "Content written to";
    qDebug() << qsDownloadPath;
    }
    pNetReply->deleteLater();
    }
    }

    I'm getting mad: it runs fine in Release, but when i launch the debugger, I get the message

    "The inferior stopped because it received a signal from the operating system
    Signal name: SIGSEGV
    Signal meaning: Segmentation Fault"

    I'm not new to Qt, but I'm new to everything QNetwork. :-(

    Thanks a lot!

    Fernando

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      connect(mpNetManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(downloadFinished()));

      You are missing the parameter of downloadFinished

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • F Offline
        F Offline
        Fernando
        wrote on last edited by SGaist
        #3

        You're right, sorry.

        Corrected .cpp source (still the same problem):

        #include "mainwindow.h"
        #include "ui_mainwindow.h"
        
        MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
        {
            ui->setupUi(this);
            initializeNetwork();
            testDownload();
        }
        
        
        MainWindow::~MainWindow()
        {
            delete ui;
            mpNetManager->deleteLater();
        }
        
        
        void MainWindow::initializeNetwork()
        {
            mpNetManager = new QNetworkAccessManager;
        }
        
        
        void MainWindow::testDownload()
        {
            if (mpNetManager)
            {
                QNetworkRequest netRequest;
                QUrl downloadURL(TEST_URL);
                netRequest.setUrl(downloadURL);
                connect(mpNetManager, SIGNAL(finished(QNetworkReply * )), this, SLOT(downloadFinished(QNetworkReply * )));
                mpNetManager->get(netRequest);
            }
        }
        
        
        void MainWindow::downloadFinished (QNetworkReply* pNetReply)
        {
            if (pNetReply)
            {
                if(pNetReply->error())
                {
                        qDebug() << "ERROR!";
                        qDebug() << pNetReply->errorString();
                }
                else
                {
                    QString    qsDownloadPath = "downloaded.txt";
                    QFile *pOutFile = new QFile(qsDownloadPath);
                    if(pOutFile->open(QFile::WriteOnly))
                    {
                        pOutFile->write(pNetReply->readAll());
                        pOutFile->flush();
                        pOutFile->close();
                    }
                    delete pOutFile;
                        qDebug() << "Download finished";
                        qDebug() << "Content written to";
                        qDebug() << qsDownloadPath;
                }
                pNetReply->deleteLater();
            }
        }
        

        [edit: Added missing coding tags SGaist]

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          What do you get if you run your application through a debugger ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • F Offline
            F Offline
            Fernando
            wrote on last edited by
            #5

            As I stated, when i launch the debugger, as soon as the "finished" signal fires I get the message

            "The inferior stopped because it received a signal from the operating system
            Signal name: SIGSEGV
            Signal meaning: Segmentation Fault"

            This is from C:\Windows\SysWOW64\ntdll.dll, instruction "rtlmovmemory"

            This only happens while debugging: the program runs fine in Release.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Can you check with a tool like Dependency Walker the libraries you are currently linking to ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • F Offline
                F Offline
                Fernando
                wrote on last edited by
                #7

                Sure:

                LIBGCC_S_DW2-1.DLL
                QT5CORED.DLL
                QT5NETWORKD.DLL
                QT5WIDGETSD.DLL
                API-MS-WIN-APPMODEL-RUNTIME-L1-1-0.DLL
                API-MS-WIN-CORE-WINRT-ERROR-L1-1-0.DLL
                API-MS-WIN-CORE-WINRT-L1-1-0.DLL
                API-MS-WIN-CORE-WINRT-ROBUFFER-L1-1-0.DLL
                API-MS-WIN-CORE-WINRT-STRING-L1-1-0.DLL
                API-MS-WIN-SHCORE-SCALING-L1-1-1.DLL
                DCOMP.DLL
                IESHIMS.DLL

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  That part looks good

                  Then let's get step by step. Does it also fail if you comment out the network stuff ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • F Offline
                    F Offline
                    Fernando
                    wrote on last edited by Fernando
                    #9

                    It debugs nicely without

                    mpNetManager->get(netRequest);

                    And it runs nicely (even with mpNetManager->get(netRequest)) when not debugging (even if the build was in debug mode).
                    To me, it's a bug in the debugger :-) , at least under Windows7-64.

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Using Qt's MinGW package ?

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • F Offline
                        F Offline
                        Fernando
                        wrote on last edited by
                        #11

                        Sorry, I was out of town.

                        Yes, using Qt's MinGW package (I don't have and don't like Visual Studio :-) ).

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          So you have MinGW 4.9 ?

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          0
                          • F Offline
                            F Offline
                            Fernando
                            wrote on last edited by
                            #13

                            Yes, MinGW 4.9.1.
                            Do you think I should file a bug report?

                            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