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. Stack Overflow error instantiating new objects
Forum Update on Monday, May 27th 2025

Stack Overflow error instantiating new objects

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 1.3k 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
    TommyTLC
    wrote on 3 Jun 2021, 13:21 last edited by
    #1

    Hello everyone,

    This post derives directly from my previous one. I thought I could make another one since this is a different problem and could help others in the future without having to read through the previous one.

    What I am trying to achieve:
    Inside the same panel I have on the left a qListWidget with different items and on the right a StackedWidget object. I would like to be able to select the items on the list and (based on which item has been selected) show the corresponding widget in the StackedWidget.

    What I have done so far:
    Until now I have created the qListWidget also adding the various items to it. I also created a WidgetClass per widget that I want to add to the StackedWidget. Now, thanks to the other users' tips I created a SIGNAL and SLOT system that should do the magic.

    The code: (ConfigurationDialog.cpp)

    ConfigurationDialog::ConfigurationDialog(QWidget* parent)
    : QDialog(parent)
    {
    ui.setupUi(this);
    setWindowFlags(Qt::WindowStaysOnTopHint);

    ui.listWidget->addItem("Text1");
    ui.listWidget->addItem("Text2");
    ui.listWidget->addItem("Text3");
    ui.listWidget->addItem("Text4");
    ui.listWidget->addItem("Text5");

    item1Configuration* item1 = new item1Configuration;
    item2Configuration* item2 = new item2Configuration;
    item3Configuration* item3 = new item3Configuration;
    item4Configuration* item4 = new item4Configuration;
    item5Configuration* item5 = new item5Configuration;

    ui.stackedWidget->addWidget(item1);
    ui.stackedWidget->addWidget(item2);
    ui.stackedWidget->addWidget(item3);
    ui.stackedWidget->addWidget(item4);
    ui.stackedWidget->addWidget(item5);

    connect(ui.listWidget, SIGNAL(itemClicked(QListWidgetItem*)),
    this, SLOT(onListItemClicked(QListWidgetItem*)));
    }

    ConfigurationDialog::~ConfigurationDialog()
    {
    }

    void ConfigurationDialog::onListItemClicked(QListWidgetItem* item)
    {
    ui.stackedWidget->setCurrentIndex(ui.listWidget->currentRow());
    }

    Now I think the logic is correct. The problem is that the application does not open anymore when I compile. Instead after a little bit of waiting a window opens up with the following error:

    Unhandled exception at 0x00007FFD5793B866 (ntdll.dll) in Application.exe: 0xC00000FD: Stack overflow (parameters: 0x0000000000000001, 0x000000190E003FF8).

    I believe this is because of the instantiation of the objects. But why is it so? How should I fix this?
    Thank you in advance.

    1 Reply Last reply
    0
    • C Online
      C Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 3 Jun 2021, 13:24 last edited by
      #2

      Use a debugger and see where exactly it crashes.

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

      T 1 Reply Last reply 3 Jun 2021, 13:26
      0
      • C Christian Ehrlicher
        3 Jun 2021, 13:24

        Use a debugger and see where exactly it crashes.

        T Offline
        T Offline
        TommyTLC
        wrote on 3 Jun 2021, 13:26 last edited by
        #3

        @Christian-Ehrlicher The debugger points me to this:

        _CRT_SECURITYCRITICAL_ATTRIBUTE
        void* __CRTDECL operator new(size_t const size)
        {
        for (;;)
        {
        if (void* const block = malloc(size)) //THIS LINE
        {
        return block;
        }

            if (_callnewh(size) == 0)
            {
                if (size == SIZE_MAX)
                {
                    __scrt_throw_std_bad_array_new_length();
                }
                else
                {
                    __scrt_throw_std_bad_alloc();
                }
            }
        
            // The new handler was successful; try to allocate again...
        }
        

        }

        1 Reply Last reply
        0
        • C Online
          C Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 3 Jun 2021, 13:28 last edited by
          #4

          You should also take a look at the backtrace so you can see from where this was called.

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

          T 1 Reply Last reply 3 Jun 2021, 13:34
          0
          • C Christian Ehrlicher
            3 Jun 2021, 13:28

            You should also take a look at the backtrace so you can see from where this was called.

            T Offline
            T Offline
            TommyTLC
            wrote on 3 Jun 2021, 13:34 last edited by
            #5

            @Christian-Ehrlicher Is "backtrace" a debugging function of VisualStudio?

            1 Reply Last reply
            0
            • T Offline
              T Offline
              TommyTLC
              wrote on 3 Jun 2021, 14:06 last edited by TommyTLC 6 Mar 2021, 14:14
              #6

              It looks like the problem comes from the instantiation of the various objects:

              item1Configuration* item1 = new item1Configuration;
              item2Configuration* item2 = new item2Configuration;
              item3Configuration* item3 = new item3Configuration;
              item4Configuration* item4 = new item4Configuration;
              item5Configuration* item5 = new item5Configuration;

              When, for example, item2 is created after item1 the application freezes.

              1 Reply Last reply
              0
              • mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on 3 Jun 2021, 15:07 last edited by
                #7

                Hi

                can you show the constructor for
                item2Configuration ?

                and also its .h

                Maybe you have some HUGE array inside or something similar as the rest of the code seems fine.

                T 1 Reply Last reply 3 Jun 2021, 15:09
                0
                • mrjjM mrjj
                  3 Jun 2021, 15:07

                  Hi

                  can you show the constructor for
                  item2Configuration ?

                  and also its .h

                  Maybe you have some HUGE array inside or something similar as the rest of the code seems fine.

                  T Offline
                  T Offline
                  TommyTLC
                  wrote on 3 Jun 2021, 15:09 last edited by
                  #8

                  @mrjj I found my mistake: I had a line instantiating the object inside its constructor. I deleted that and now it all works, thank you guys!

                  mrjjM 1 Reply Last reply 3 Jun 2021, 15:12
                  0
                  • T TommyTLC
                    3 Jun 2021, 15:09

                    @mrjj I found my mistake: I had a line instantiating the object inside its constructor. I deleted that and now it all works, thank you guys!

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 3 Jun 2021, 15:12 last edited by mrjj 6 Mar 2021, 15:13
                    #9

                    @TommyTLC
                    Super :)

                    1 Reply Last reply
                    0

                    1/9

                    3 Jun 2021, 13:21

                    • Login

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