QTDesigner Widget crashs, when trying to do anything with its Widgets.
-
hi there..
I created a simple Widget with QTDesigner, that only contains one QVBoxLayout, called "VLays".
The *.ui File:
<?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>TGS_Widget_AssetList</class> <widget class="QWidget" name="TGS_Widget_AssetList"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>400</width> <height>668</height> </rect> </property> <property name="sizePolicy"> <sizepolicy hsizetype="Expanding" vsizetype="Expanding"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> <property name="windowTitle"> <string>TGS_Widget_AssetList</string> </property> <layout class="QVBoxLayout" name="verticalLayout"> <property name="spacing"> <number>0</number> </property> <property name="leftMargin"> <number>4</number> </property> <property name="topMargin"> <number>4</number> </property> <property name="rightMargin"> <number>4</number> </property> <property name="bottomMargin"> <number>4</number> </property> <item> <layout class="QVBoxLayout" name="VLays"> <property name="spacing"> <number>0</number> </property> </layout> </item> </layout> </widget> <resources/> <connections/> </ui>
The *.h File:
#ifndef TGS_WIDGET_ASSETLIST_H #define TGS_WIDGET_ASSETLIST_H #include <QWidget> #include <boost/property_tree/ptree.hpp> #include <iostream> QT_BEGIN_NAMESPACE namespace Ui { class TGS_Widget_AssetList; } QT_END_NAMESPACE class TGS_Widget_AssetList : public QWidget { Q_OBJECT public: explicit TGS_Widget_AssetList(QWidget *parent = nullptr); ~TGS_Widget_AssetList() override; void _test(); private: Ui::TGS_Widget_AssetList *ui; }; #endif //TGS_WIDGET_ASSETLIST_H
And the *.cpp File:
#include "tgs_widget_assetlist.h" #include "ui_TGS_Widget_AssetList.h" TGS_Widget_AssetList::TGS_Widget_AssetList(QWidget *parent) : QWidget(parent), ui(new Ui::TGS_Widget_AssetList) { ui->setupUi(this); std::cout << "Start Construct" << std::endl; ui->VLays->addStretch(); std::cout << "Constructed" << std::endl; TGS_Widget_AssetList::~TGS_Widget_AssetList() { delete ui; } void TGS_Widget_AssetList::_test() { std::cout << "Hello" << std::endl; }
EDIT 1:
I added this to the test Function:if(ui->VLays->isEmpty()){ std::cout << "VLays is empty" << std::endl; }else{ std::cout << "VLays is filled with Stuff" << std::endl; }
But it crashes, without firing the couts...
This Widget is created.. as child of a scrollArea..
This way:[...] // _assetList is a Pointer in the privates of the MainWindow if(_assetList == nullptr){ _assetList = new TGS_Widget_AssetList(); //Add the List object to the layout of the ScrollArea Contents ui->scrollArea_AssetListContents->layout()->addWidget(_assetList); _assetList->show(); } [...]
but neither the first cout, nor the second one is fired. As if the constructor is never called.
So.. whenever i want to interact with anything, or just want to cout things in the constructor.. the whole app crashes with exit code -1073741819 (0xC0000005)...
But i am able to fire the test function... and it prints the cout..
So.. i compared the files with my previously created QWidgets, and can´t find a Mistake, that causes that Problem..
Perhaps you guys can help me out here.. since i´m confused, what the Problem could be..
#===============================================
EDIT 2 - SOLUTION:
found out, that i needed to create a new Pointer in the Declaration of the .h File..Means..
TGS_Widget_AssetList * _assetList;
Wasn´t enough...
I needed to doe:TGS_Widget_AssetList *_assetList = new TGS_Widget_AssetList(this); or auto *_assetList = new TGS_Widget_AssetList(this);
-
@BDC_Patrick
If you say the program "crashes", compile it for debug, run it in the debugger, and look at the stack trace when it crashes.Put breakpoints or
qDebug()
messages into, say, the constructor if you think that is not being executed. Step over/into lines in your code to follow what is being executed. -
@JonB
Thanks.. found out, that i needed to create a new Pointer in the Declaration of the .h File..Means..
TGS_Widget_AssetList * _assetList;
Wasn´t enough...
I needed to do:TGS_Widget_AssetList *_assetList = new TGS_Widget_AssetList(this); or auto *_assetList = new TGS_Widget_AssetList(this);
Now it works.. i will update my initial post here