Qt process ends forcefully when manipulating widgets
-
Greetings to all.
I'm trying to run a Qt Widgets Application but everytime I try to modify a specific widget on a Dialog (not MainWindow, everything works fine in that file) the program crashes and the process end forcefully with the following messages:
23:26:51: The program has unexpectedly finished.
23:26:51: The process was ended forcefully.I'm not quite sure what is the situation here. I have an object that runs some queries in order to fill 6 QHash containers and a QSqlDatabase object as well as class members but that's it.
TLDR: Program crashes when trying to access ui members and operations in a specific Dialog diferent from Main Window.
-
Crash means you definitely accessing some invalid pointer. Can show your sample code where it fails ?
-
ui->label_nombre->setText(zeze);
It happens with any Widget, wether it is a label, qlistwidget, qlineedit, etc.
Is the ui pointer set up in a wrong way? This is the Dialog class:
#ifndef STORE_H
#define STORE_H#include <QDialog>
#include <administrador.h>
#include <QMessageBox>namespace Ui {
class Store;
}class Store : public QDialog
{
Q_OBJECTpublic:
explicit Store(QWidget *parent = nullptr);
~Store();private:
Ui::Store *ui;
administrador admin;
QSqlDatabase db;
}; -
this is the constructor definition
Store::Store(QWidget *parent) :
QDialog(parent),
ui(new Ui::Store)
{
setWindowTitle("Tienda");
db = QSqlDatabase::database();
admin.fillContainers();QHash<QString,sucursal> sucursales = admin.getSucursales(); QHash<QString, celular> celulares = admin.getCelulares(); QHash<QString, solicitudCompra> solicitudes = admin.getSolicitudes(); QHash<QString, compra> compras = admin.getCompras(); QHash<QString, documento> documentos = admin.getDocumentos(); QHash<QString, Cliente> clientes = admin.getClientes(); sucursal sanAndres = sucursales["idSuc1"]; sucursal sonata = sucursales["idSuc2"]; sucursal pte = sucursales["idSuc3"]; sucursal serdan = sucursales["idSuc4"]; sucursal ange = sucursales["idSuc5"]; QHash<QString,celular>::iterator celtemp; celular celtemporal; celtemp = celulares.find("idXR"); QString zeze = celtemp.value().getAtributo(0); qDebug() << zeze; ui->label_nombre->setText(zeze); ui->setupUi(this);
}
-
Hi and welcome to devnet,
ui->setupUi(this);
must be called prior to any access to anything you added through designer.