The project is set up correctly I guess, I've got no build errors and all classes are being recognized. The problem is that when I add the line
ui->lineEdit->setCompleter(completer);
that should set the completer
for my lineEdit
the application won't launch and it shows an output error
Process finished with exit code -1073741819 (0xC0000005)
Here are the project files
.pro
######################################################################
# Automatically generated by qmake (3.1) Thu Jul 18 13:48:43 2019
######################################################################
TEMPLATE = app
TARGET = "Laboratorio 5"
INCLUDEPATH += .
QT += gui core widgets
# The following define makes your compiler warn you if you use any
# feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
# Input
HEADERS += DiskUsageAnalyzer.h FileSystemModel.h
FORMS += DiskUsageAnalyzer.ui
SOURCES += DiskUsageAnalyzer.cpp FileSystemModel.cpp main.cpp
main.cpp
#include "DiskUsageAnalyzer.h"
int main(int argc, char** argv) {
QApplication application(argc, argv);
DiskUsageAnalyzer diskUsageAnalyzer;
diskUsageAnalyzer.show();
return application.exec();
}
FileSystemModel.h
#include <QtWidgets>
class FileSystemModel : public QFileSystemModel {
Q_OBJECT
public:
explicit FileSystemModel(QObject *parent = nullptr);
QVariant data(const QModelIndex &index, int role) const override;
};
FileSystemModel.cpp
#include "FileSystemModel.h"
FileSystemModel::FileSystemModel(QObject *parent) : QFileSystemModel(parent) {
}
QVariant FileSystemModel::data(const QModelIndex &index, int role) const {
if (role == Qt::DisplayRole && index.column() == 0) {
QString path = QDir::toNativeSeparators(filePath(index));
if (path.endsWith(QDir::separator()))
path.chop(1);
return path;
}
return QFileSystemModel::data(index, role);
}
DiskUsageAnalyzer.h
#include "ui_DiskUsageAnalyzer.h"
#include "FileSystemModel.h"
class DiskUsageAnalyzer : public QMainWindow {
Q_OBJECT
private:
Ui_DiskUsageAnalyzer *ui;
FileSystemModel *dirModel;
QCompleter *completer;
public:
explicit DiskUsageAnalyzer(QWidget *parent = nullptr);
~DiskUsageAnalyzer() override;
public slots:
signals:
};
DiskUsageAnalyzer.cpp
#include "DiskUsageAnalyzer.h"
DiskUsageAnalyzer::DiskUsageAnalyzer(QWidget *parent) : QMainWindow(parent) {
ui = new Ui::DiskUsageAnalyzer;
dirModel = new FileSystemModel(this);
dirModel->setRootPath("");
completer = new QCompleter(this);
ui->lineEdit->setCompleter(completer);
ui->setupUi(this);
}
DiskUsageAnalyzer::~DiskUsageAnalyzer() {
delete ui;
}
Sorry for not providing a minimal reproducible example but I'm new to Qt and I have no clue on how to reduce all files at minimum.
User contributions licensed under CC BY-SA 3.0