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. Qut of memory in QVector
QtWS25 Last Chance

Qut of memory in QVector

Scheduled Pinned Locked Moved Solved General and Desktop
runtime error
14 Posts 4 Posters 4.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.
  • T Offline
    T Offline
    Tikani
    wrote on last edited by Tikani
    #1

    Good day everyone!
    I have such a problem - I need to subclass QAbstractTableModel to write my own one, which has capability to get data remotely from a server with REST. OK, a build is successful, but on app start this error rises:
    Out of memory in ..\..\include/QtCore/../../src/corelib/tools/qvector.h, line 551 terminate called without an active exception under Qt 5.9.6
    and
    Out of memory in ..\..\include/QtCore/../../src/corelib/tools/qvector.h, line 563 terminate called without an active exception under Qt 5.11
    taskmodel.h

    #include <QAbstractTableModel>
    #include "commons.h"
    
    class TaskModel : public QAbstractTableModel
    {
        Q_OBJECT
    
    public:
        TaskModel(QObject *parent = nullptr);
        ~TaskModel() override;
    
        int rowCount(const QModelIndex &parent = QModelIndex()) const override;
        int columnCount(const QModelIndex &parent = QModelIndex()) const override;
    
        QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
        QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
    
        void setCredentials(const QString&, const QString&, const QString&);
    
    public slots:
        void suspendTask();
    
    private slots:
    
    private:
    
        QList<Task> *tasks = nullptr; // Внутреннее хранилище всех задач
    
        QString baseUrl;
        QString login;
        QString password;
    };
    

    taskmodel.cpp

    #include "taskmodel.h"
    
    TaskModel::TaskModel(QObject *parent) : QAbstractTableModel (parent) {}
    TaskModel::~TaskModel() {}
    
    int TaskModel::rowCount(const QModelIndex &parent) const {}
    
    int TaskModel::columnCount(const QModelIndex &parent) const
    {
        Q_UNUSED(parent)
        return 3;
    }
    
    QVariant TaskModel::data(const QModelIndex &index, int role) const {}
    
    QVariant TaskModel::headerData(int section, Qt::Orientation orientation, int role) const
    {
        if(role == Qt::DisplayRole) {
            if(orientation == Qt::Horizontal) {
                switch (section) {
                    case 0:
                        return QString("Код");
                    case 1:
                        return QString("Описание");
                    case 2:
                        return QString("В работе");
                }
            }
        }
        return QVariant();
    }
    
    void TaskModel::setCredentials(const QString &baseUrl, const QString &login, const QString &password)
    {
        this->baseUrl = baseUrl;
        this->login = login;
        this->password = password;
    }
    
    void TaskModel::suspendTask() {}
    

    mainwindow.h

    #include "cookieauthorizator.h"
    
    #include <QMainWindow>
    #include <QCloseEvent>
    #include <QSystemTrayIcon>
    #include "taskmodel.h"
    
    namespace Ui {
    class MainWindow;
    }
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        MainWindow(const QApplication& app, QWidget *parent = nullptr);
        ~MainWindow() override;
    
    protected:
        void closeEvent(QCloseEvent*) override;
        bool nativeEvent(const QByteArray &eventType, void *message, long *result) override;
    
    private slots:
        void iconActivated(QSystemTrayIcon::ActivationReason);
    
        void on_acGeneral_triggered();
    
    private:
        Ui::MainWindow *ui;
        QSystemTrayIcon *trayIcon;
        QMenu *menu;
        QAction *quit;
    
        TaskModel *model; 
    };
    

    mainwindow.cpp

    MainWindow::MainWindow(const QApplication &app, QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow), trayIcon(new QSystemTrayIcon(this)), menu(new QMenu(this)), quit(new QAction("Выход",this)), model(new TaskModel(this))
    {
        WTSRegisterSessionNotification(reinterpret_cast<HWND>(MainWindow::winId()), NOTIFY_FOR_THIS_SESSION); // Подписываем главное окно приложения на сообщения блокировки/разблокировки текущей сессии (проще говоря, экрана)
        ui->setupUi(this);
        ui->tvTask->setModel(model);
        menu->addAction(quit);
        trayIcon->setIcon(this->style()->standardIcon(QStyle::SP_ComputerIcon));
        connect(quit, &QAction::triggered, &app, &QApplication::exit);
        connect(trayIcon, &QSystemTrayIcon::activated, this, &MainWindow::iconActivated);
        trayIcon->show();
    }
    

    What am I doing wrong? I don't use QVector in my code directly, as you can see. The error rises in the guts of the framework class and I don't know why :(((((((
    P.S. Task is a simple struct like this in commons.h:

    struct Task {
    QString x;
    QString y;
    bool z;
    };
    

    P.P.S. Complier - MinGW 5.3.0 32bit; OS: Windows 10

    jsulmJ 1 Reply Last reply
    0
    • T Tikani

      Good day everyone!
      I have such a problem - I need to subclass QAbstractTableModel to write my own one, which has capability to get data remotely from a server with REST. OK, a build is successful, but on app start this error rises:
      Out of memory in ..\..\include/QtCore/../../src/corelib/tools/qvector.h, line 551 terminate called without an active exception under Qt 5.9.6
      and
      Out of memory in ..\..\include/QtCore/../../src/corelib/tools/qvector.h, line 563 terminate called without an active exception under Qt 5.11
      taskmodel.h

      #include <QAbstractTableModel>
      #include "commons.h"
      
      class TaskModel : public QAbstractTableModel
      {
          Q_OBJECT
      
      public:
          TaskModel(QObject *parent = nullptr);
          ~TaskModel() override;
      
          int rowCount(const QModelIndex &parent = QModelIndex()) const override;
          int columnCount(const QModelIndex &parent = QModelIndex()) const override;
      
          QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
          QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
      
          void setCredentials(const QString&, const QString&, const QString&);
      
      public slots:
          void suspendTask();
      
      private slots:
      
      private:
      
          QList<Task> *tasks = nullptr; // Внутреннее хранилище всех задач
      
          QString baseUrl;
          QString login;
          QString password;
      };
      

      taskmodel.cpp

      #include "taskmodel.h"
      
      TaskModel::TaskModel(QObject *parent) : QAbstractTableModel (parent) {}
      TaskModel::~TaskModel() {}
      
      int TaskModel::rowCount(const QModelIndex &parent) const {}
      
      int TaskModel::columnCount(const QModelIndex &parent) const
      {
          Q_UNUSED(parent)
          return 3;
      }
      
      QVariant TaskModel::data(const QModelIndex &index, int role) const {}
      
      QVariant TaskModel::headerData(int section, Qt::Orientation orientation, int role) const
      {
          if(role == Qt::DisplayRole) {
              if(orientation == Qt::Horizontal) {
                  switch (section) {
                      case 0:
                          return QString("Код");
                      case 1:
                          return QString("Описание");
                      case 2:
                          return QString("В работе");
                  }
              }
          }
          return QVariant();
      }
      
      void TaskModel::setCredentials(const QString &baseUrl, const QString &login, const QString &password)
      {
          this->baseUrl = baseUrl;
          this->login = login;
          this->password = password;
      }
      
      void TaskModel::suspendTask() {}
      

      mainwindow.h

      #include "cookieauthorizator.h"
      
      #include <QMainWindow>
      #include <QCloseEvent>
      #include <QSystemTrayIcon>
      #include "taskmodel.h"
      
      namespace Ui {
      class MainWindow;
      }
      
      class MainWindow : public QMainWindow
      {
          Q_OBJECT
      
      public:
          MainWindow(const QApplication& app, QWidget *parent = nullptr);
          ~MainWindow() override;
      
      protected:
          void closeEvent(QCloseEvent*) override;
          bool nativeEvent(const QByteArray &eventType, void *message, long *result) override;
      
      private slots:
          void iconActivated(QSystemTrayIcon::ActivationReason);
      
          void on_acGeneral_triggered();
      
      private:
          Ui::MainWindow *ui;
          QSystemTrayIcon *trayIcon;
          QMenu *menu;
          QAction *quit;
      
          TaskModel *model; 
      };
      

      mainwindow.cpp

      MainWindow::MainWindow(const QApplication &app, QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::MainWindow), trayIcon(new QSystemTrayIcon(this)), menu(new QMenu(this)), quit(new QAction("Выход",this)), model(new TaskModel(this))
      {
          WTSRegisterSessionNotification(reinterpret_cast<HWND>(MainWindow::winId()), NOTIFY_FOR_THIS_SESSION); // Подписываем главное окно приложения на сообщения блокировки/разблокировки текущей сессии (проще говоря, экрана)
          ui->setupUi(this);
          ui->tvTask->setModel(model);
          menu->addAction(quit);
          trayIcon->setIcon(this->style()->standardIcon(QStyle::SP_ComputerIcon));
          connect(quit, &QAction::triggered, &app, &QApplication::exit);
          connect(trayIcon, &QSystemTrayIcon::activated, this, &MainWindow::iconActivated);
          trayIcon->show();
      }
      

      What am I doing wrong? I don't use QVector in my code directly, as you can see. The error rises in the guts of the framework class and I don't know why :(((((((
      P.S. Task is a simple struct like this in commons.h:

      struct Task {
      QString x;
      QString y;
      bool z;
      };
      

      P.P.S. Complier - MinGW 5.3.0 32bit; OS: Windows 10

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

      @Tikani Did you try to run your app through debugger to see where the crash happens? In the code you posted I don't see anything obvious.

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

      T 1 Reply Last reply
      2
      • jsulmJ jsulm

        @Tikani Did you try to run your app through debugger to see where the crash happens? In the code you posted I don't see anything obvious.

        T Offline
        T Offline
        Tikani
        wrote on last edited by Tikani
        #3

        @jsulm yes, I tried, but error happens inside the Qt class, not in my code, so, debugger shows me an ugly assembler code. As far I understand, I need to rebuild the whole Qt with debug information/symbols to be able to get human-friendly debuggin proccess. I use Windows and default build environment from the opensource installator from the official Qt site (Qt 5.9.6 or Qt 5.11, MinGW 5.3.0 32bit) and rebuild Qt from source not under Linux - such a pain.

        jsulmJ 1 Reply Last reply
        0
        • T Tikani

          @jsulm yes, I tried, but error happens inside the Qt class, not in my code, so, debugger shows me an ugly assembler code. As far I understand, I need to rebuild the whole Qt with debug information/symbols to be able to get human-friendly debuggin proccess. I use Windows and default build environment from the opensource installator from the official Qt site (Qt 5.9.6 or Qt 5.11, MinGW 5.3.0 32bit) and rebuild Qt from source not under Linux - such a pain.

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

          @Tikani But it could help to see where in your app you are when the crash happens and in which state the app is (values of variables, ...). Bugs in frameworks are rare, so most probably it is something in your app, but actual crash happens inside Qt (but not because of a Qt bug).

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

          T 1 Reply Last reply
          0
          • jsulmJ jsulm

            @Tikani But it could help to see where in your app you are when the crash happens and in which state the app is (values of variables, ...). Bugs in frameworks are rare, so most probably it is something in your app, but actual crash happens inside Qt (but not because of a Qt bug).

            T Offline
            T Offline
            Tikani
            wrote on last edited by Tikani
            #5

            @jsulm Ok, then I try to rebuild Qt with debug information and post here a link to GitHub with my project (it's opensource) as well, may be then things get clearer for true Jedis :D may be there is a need in a big picture to resolve the problem.

            jsulmJ 2 Replies Last reply
            0
            • T Tikani

              @jsulm Ok, then I try to rebuild Qt with debug information and post here a link to GitHub with my project (it's opensource) as well, may be then things get clearer for true Jedis :D may be there is a need in a big picture to resolve the problem.

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

              @Tikani No! There is no need to rebuild Qt at this stage! I don't ask you to debug Qt - it will most probably not help you. Simply run your app through debugger until it crashes and see where in your app you are at that time.
              In most cases (from my own experience) if your app crashes somewhere in Qt it is NOT Qt but your app which is doing something wrong.

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

              1 Reply Last reply
              2
              • T Tikani

                @jsulm Ok, then I try to rebuild Qt with debug information and post here a link to GitHub with my project (it's opensource) as well, may be then things get clearer for true Jedis :D may be there is a need in a big picture to resolve the problem.

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

                @Tikani Also you can post stack trace after crash here - it can help to find the issue

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

                T 1 Reply Last reply
                2
                • jsulmJ jsulm

                  @Tikani Also you can post stack trace after crash here - it can help to find the issue

                  T Offline
                  T Offline
                  Tikani
                  wrote on last edited by Tikani
                  #8

                  @jsulm OK, I got the point. I attach stacktrace and full code a little bit later - I need to go to work now :( Thanks anyway for the fastness of responses - now I'm confident that my issue would be resolved eventually with help of the community.

                  1 Reply Last reply
                  0
                  • mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    Hi
                    I see that you are using 32 bit.
                    How many model items do you add ?

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

                      Hi,

                      @Tikani said in Qut of memory in QVector:

                      QList<Task> *tasks = nullptr; // Внутреннее хранилище всех задач

                      Why are you using a pointer for tasks ? I don't see it initialised anywhere.

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

                      T 1 Reply Last reply
                      2
                      • SGaistS SGaist

                        Hi,

                        @Tikani said in Qut of memory in QVector:

                        QList<Task> *tasks = nullptr; // Внутреннее хранилище всех задач

                        Why are you using a pointer for tasks ? I don't see it initialised anywhere.

                        T Offline
                        T Offline
                        Tikani
                        wrote on last edited by Tikani
                        #11

                        @SGaist It is just an inner storage over which subclassed model works. I forgot to comment it after my experiments with fields and its types, when I tried to locate a culprit of a aprogram crash. Anyway, it doesn't initialize in any way, it is just empty nullptr junk pointer.
                        By the way, here stacktrace comes:

                        1  msvcrt!abort                                                                        0x7732b3fb 
                        2  libstdc++-6!_ZN9__gnu_cxx27__verbose_terminate_handlerEv                            0x1768085d 
                        3  libstdc++-6!_ZN10__cxxabiv111__terminateEPFvvE                                      0x17679399 
                        4  libstdc++-6!_ZSt9terminatev                                                         0x17713930 
                        5  qt_check_pointer                                         qglobal.cpp           3050 0x6b98abc1 
                        6  QVector<QHeaderViewPrivate::SectionItem>::reallocData    qvector.h             551  0xde2dc07  
                        7  QVector<QHeaderViewPrivate::SectionItem>::resize         qvector.h             416  0xde2e4ce  
                        8  QHeaderViewPrivate::createSectionItems                   qheaderview.cpp       3530 0xdcd1a3d  
                        9  QHeaderView::initializeSections                          qheaderview.cpp       2279 0xdcd2572  
                        10 QHeaderView::initializeSections                          qheaderview.cpp       2205 0xdcd5918  
                        11 QHeaderView::reset                                       qheaderview.cpp       1774 0xdcd9584  
                        12 QAbstractItemView::setModel                              qabstractitemview.cpp 748  0xdcc0764  
                        13 QHeaderView::setModel                                    qheaderview.cpp       408  0xdcd94e0  
                        14 QTableView::setModel                                     qtableview.cpp        1136 0xdd140d6  
                        15 MainWindow::MainWindow                                   mainwindow.cpp        15   0x401910   
                        16 qMain                                                    main.cpp              11   0x4016f4   
                        17 WinMain *16                                              qtmain_win.cpp        104  0x404d85   
                        18 main                                                                                0x40934d   
                        
                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          One more thing, your data method is empty, it should at least contain return QVariant();.

                          You don't need to pass your QApplication instance as parameter. You can access it using the qApp macro.

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

                          T 1 Reply Last reply
                          3
                          • SGaistS SGaist

                            One more thing, your data method is empty, it should at least contain return QVariant();.

                            You don't need to pass your QApplication instance as parameter. You can access it using the qApp macro.

                            T Offline
                            T Offline
                            Tikani
                            wrote on last edited by
                            #13

                            @SGaist Thanks, the issue is solved. There was a need in return QVariant() indeed. Mark as closed.

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

                              There's always a need to return something when your method has a return type. If you don't know what to return at first then return a default value.

                              Also, always take into account the warnings the compiler throws at you (there is one for functions not returning anything when their signature contains a return type). As the old saying goes: a compiler warning ignored today is a catastrophic crash in production tomorrow.

                              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
                              1

                              • Login

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