I have this text file:
Name 1 Email 1
Name 2 Email 2
Name 3 Email 3
Name 4 Email 4
Name 5 Email 5
This is a list of employees with their emails. I want to make a list in a dialog window with their names displayed there. I thought this was a good way to print out the text file on the dialog window but it isn't working.
employees_dialog.cpp
#include "employees_dialog.h"
#include "ui_employees_dialog.h"
#include <QtCore/QFile>
#include <QtCore/QTextStream>
employees_dialog::employees_dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::employees_dialog)
{
ui->setupUi(this);
getTextFile();
}
employees_dialog::~employees_dialog()
{
delete ui;
}
void employees_dialog::getTextFile()
{
QFile myFile(":/employees.txt");
myFile.open(QIODevice::ReadOnly);
QTextStream textStream(&myFile);
QString line = textStream.readAll();
myFile.close();
ui->textEdit->setPlainText(line);
}
This is the header file.
#ifndef EMPLOYEES_DIALOG_H
#define EMPLOYEES_DIALOG_H
#include <QDialog>
namespace Ui {
class employees_dialog;
}
class employees_dialog : public QDialog
{
Q_OBJECT
public:
explicit employees_dialog(QWidget *parent = 0);
~employees_dialog();
private slots:
private:
Ui::employees_dialog *ui;
void getTextFile();
};
#endif // EMPLOYEES_DIALOG_H
So the textEdit
in the UI should display the text file. But it's just blank white. I have the file in Qt Resources File. The debugger doesn't give any errors the application itself is just working fine but the text won't appear in the textEdit
.
By the way, I'm new to Qt.