Below is the code, Header File QtGuiApplication1.h
#pragma once
#include <QtWidgets/QMainWindow>
#include "ui_QtGuiApplication1.h"
class QtGuiApplication1 : public QMainWindow
{
Q_OBJECT
public:
QtGuiApplication1(QWidget *parent = Q_NULLPTR);
private:
Ui::QtGuiApplication1Class ui;
public slots:
void on_pushButton_clicked();
};
Source File Code
#include "QtGuiApplication1.h"
#include<qdebug.h>
#include <qfiledialog.h>
#include <qlabel.h>
#include<qlineedit.h>
#include <qgridlayout.h>
QtGuiApplication1::QtGuiApplication1(QWidget *parent) :
QMainWindow(parent)
{
ui.setupUi(this);
}
void QtGuiApplication1::on_pushButton_clicked()
{
qDebug() <<__FUNCTION__;
QFileDialog dialogBox;
QLabel *passwordLabel = NULL;
QLabel *message = NULL;
QLineEdit *password = NULL;
dialogBox.setAcceptMode(QFileDialog::AcceptOpen);
dialogBox.setNameFilter("files(*.text)");
dialogBox.setOption(QFileDialog::DontUseNativeDialog);
dialogBox.setStyleSheet("background:white;color: black;");
QGridLayout *layout = NULL;
layout = (QGridLayout*)dialogBox.layout();
if (layout != NULL)
{
passwordLabel = new QLabel("Enter Password:");
if (passwordLabel != NULL)
{
layout->addWidget(passwordLabel, 4, 0);
}
else
{
qDebug() << __FUNCTION__;
}
message = new QLabel("Please use vlc to play this file");
if (message != NULL)
{
layout->addWidget(message, 5, 0, 2, 2);
}
else
{
qDebug() << __FUNCTION__;
}
password = new QLineEdit();
if (password != NULL)
{
layout->addWidget(password, 4, 1);
password->setEchoMode(QLineEdit::Password);
}
else
{
qDebug() << __FUNCTION__;
}
try {
int status = dialogBox.exec();
if (status)
{
QStringList FileNameList = dialogBox.selectedFiles();
}
}
catch (...)
{
qDebug()<<__FUNCTION__;
}
}
}
Ui File QtGuiApplication1.ui
<?xml version="1.0" encoding="UTF-8"?> <ui version="4.0">
<class>QtGuiApplication1Class</class>
<widget class="QMainWindow" name="QtGuiApplication1Class">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>600</width>
<height>400</height>
</rect>
</property>
<property name="windowTitle">
<string>QtGuiApplication1</string>
</property>
<widget class="QWidget" name="centralWidget">
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>170</x>
<y>140</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>PushButton</string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>600</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
<widget class="QStatusBar" name="statusBar"/>
</widget> <layoutdefault spacing="6" margin="11"/>
<resources>
<include location="QtGuiApplication1.qrc"/>
</resources> <connections/> </ui>
I need to create a custom dialog box with password feature to save a file. It's working fine fine but If I try to open dialog box and in that If I delete and create multiple folders around 20 times or more than that then it crashes. I am not getting why does it crashes on calling exec() function for QFileDialog. Please help.
Attached Debugger logs below:
The thread 0x47b0 has exited with code 0 (0x0). The thread 0x640 has exited with code 0 (0x0). The thread 0x986c has exited with code 0 (0x0). The thread 0x9898 has exited with code 0 (0x0). The thread 0x6704 has exited with code 0 (0x0). The thread 0x5328 has exited with code 0 (0x0). The thread 0x193c has exited with code 0 (0x0). The thread 0x9698 has exited with code 0 (0x0). The thread 0x638 has exited with code 0 (0x0). The thread 0x80e0 has exited with code 0 (0x0). The thread 0x68c8 has exited with code 0 (0x0). The thread 0xa0d8 has exited with code 0 (0x0). The thread 0x4684 has exited with code 0 (0x0). ASSERT failure in QList::at: "index out of range", file c:\users\qt\work\qt\qtbase\include\qtcore../../src/corelib/tools/qlist.h, line 541 Debug Error!
Program: C:\Qt\Qt5.9.2\5.9.2\msvc2015_64\bin\Qt5Cored.dll Module: 5.9.2 File: c:\users\qt\work\qt\qtbase\include\qtcore../../src/corelib/tools/qlist.h Line: 541
ASSERT failure in QList::at: "index out of range", file c:\users\qt\work\qt\qtbase\include\qtcore../../src/corelib/tools/qlist.h, line 541
(Press Retry to debug the application) QtGuiApplication1.exe has triggered a breakpoint.