Ниже приведен код, файл заголовка 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();
};
Исходный код файла
#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__;
}
}
}
Файл пользовательского интерфейса 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>
Мне нужносоздать настраиваемое диалоговое окно с функцией пароля для сохранения файла.Он работает нормально, но если я пытаюсь открыть диалоговое окно и в этом случае, если я удаляю и создаю несколько папок примерно в 20 или более раз, то происходит сбой.Я не понимаю, почему происходит сбой при вызове функции exec () для QFileDialog.Пожалуйста, помогите.
Прикрепленные журналы отладчика ниже:
Поток 0x47b0 завершился с кодом 0 (0x0).Нить 0x640 вышла с кодом 0 (0x0).Нить 0x986c вышла с кодом 0 (0x0).Нить 0x9898 вышла с кодом 0 (0x0).Нить 0x6704 вышла с кодом 0 (0x0).Нить 0x5328 вышла с кодом 0 (0x0).Нить 0x193c вышла с кодом 0 (0x0).Нить 0x9698 вышла с кодом 0 (0x0).Нить 0x638 вышла с кодом 0 (0x0).Нить 0x80e0 вышла с кодом 0 (0x0).Нить 0x68c8 вышла с кодом 0 (0x0).Поток 0xa0d8 вышел с кодом 0 (0x0).Нить 0x4684 вышла с кодом 0 (0x0).Ошибка ASSERT в QList :: at: «индекс вне диапазона», файл c: \ users \ qt \ work \ qt \ qtbase \ include \ qtcore ../../ src / corelib / tools / qlist.h, строка 541Ошибка отладки!
Программа: C: \ Qt \ Qt5.9.2 \ 5.9.2 \ msvc2015_64 \ bin \ Qt5Cored.dll Модуль: 5.9.2 Файл: c: \ users \ qt \ work \ qt \ qtbase\ include \ qtcore ../../ src / corelib / tools / qlist.h Строка: 541
Ошибка ASSERT в QList :: at: «индекс вне диапазона», файл c: \ users \ qt\ work \ qt \ qtbase \ include \ qtcore ../../ src / corelib / tools / qlist.h, строка 541
(Нажмите Retry для отладки приложения) QtGuiApplication1.exe вызвал точку останова.