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. [SOLVED] tableWidget causes the program to finish unexpectedly
QtWS25 Last Chance

[SOLVED] tableWidget causes the program to finish unexpectedly

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 2.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.
  • D Offline
    D Offline
    dndeed
    wrote on last edited by
    #1

    Hi. I am trying to add in fields to a table widget. I have a widget created in my .ui file, and I'm trying to add to it. For some reason, the program is quitting unexpectedly without adding the object.

    My code is:
    @
    ui->tableWidget->insertRow(0);
    //QCheckBox* checkBox = newQCheckBox; //commented out until I can at least create an empty row
    //ui->tableWidget->setCellWidget(0,0,checkBox);
    @

    Does anyone know why this would cause an unexpected crash with no error message displayed? If not, are there any methods to debug this problem?

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

      Hi,

      You didn't set any QTableWidgetItem on the new row so it can't contain anything

      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
      • D Offline
        D Offline
        dndeed
        wrote on last edited by
        #3

        I'm sorry, I don't quite understand. I thought the insertRow command only took the one integer as an augment. Is the QTableWidgetItem set before or after the insertRow?

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          where does the program crash?
          Run it in QtCreator (for example) and post the stack trace of the crash.
          Hard to tell where the cause is with just a single line of code.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dndeed
            wrote on last edited by
            #5

            The program crashes inside the insertRow line. I added
            @
            qDebug() << "Before Insert";
            ui->tableWidget->insertRow(0);
            qDebug() << "After Insert";
            @

            and my output is
            Starting C:\blabla\TheMAPStore...
            Before Insert
            The program has unexpectedly finished.
            C:\blabla\TheMAPStore exited with code -1073741819

            I didn't notice that error code before. I'll look into that and see if it explains things for me.

            EDIT: It seems this error code has to do with missing dll's. I am using #include's to include QTableWidget and QCheckBox. Do I need to manually add those dll's to my project file? If so, where are they found?

            1 Reply Last reply
            0
            • raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by
              #6

              did you probably forgot to call
              @ui->setupUi(this);@
              in your constructor?

              Please show some more code...

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              0
              • D Offline
                D Offline
                dndeed
                wrote on last edited by
                #7

                main.cpp:
                @
                int main(int argc, char *argv[])
                {
                QApplication a(argc, argv);

                MainWindow w;
                w.show();
                
                return a.exec&#40;&#41;;
                

                }
                @

                mainwindow.cpp:
                @
                #include "mainwindow.h"
                #include "ui_mainwindow.h"

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

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

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  dndeed
                  wrote on last edited by
                  #8

                  Oh, I'm an idiot. setupUi(this) needs to come first. Thanks for everyone help!

                  1 Reply Last reply
                  0
                  • raven-worxR Offline
                    raven-worxR Offline
                    raven-worx
                    Moderators
                    wrote on last edited by
                    #9

                    you try to access the tablewidget before you are initializing it with setupUi() ...

                    --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                    If you have a question please use the forum so others can benefit from the solution in the future

                    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