[SOLVED] tableWidget causes the program to finish unexpectedly
-
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?
-
Hi,
You didn't set any QTableWidgetItem on the new row so it can't contain anything
-
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. -
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 -1073741819I 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?
-
did you probably forgot to call
@ui->setupUi(this);@
in your constructor?Please show some more code...
-
main.cpp:
@
int main(int argc, char *argv[])
{
QApplication a(argc, argv);MainWindow w; w.show(); return a.exec();
}
@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;
}
@ -
you try to access the tablewidget before you are initializing it with setupUi() ...