I tried to make a small example containing the critical code, but it is not exact the same, since the program already crashes loading the file.
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
MainWindow w;
w.show();
return a.exec();
}
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGui/QMainWindow>
#include <QtGui>
{
Q_OBJECT
public:
~MainWindow();
private:
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGui/QMainWindow>
#include <QtGui>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
private:
QLabel *label;
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
#include "mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
){
this->setCentralWidget(label);
if(f.
open(QFile::ReadOnly)) {
this->label->setText(s.readAll()); // Crash
} else {
this->label->setText(tr("File ") + filePath + tr(" could not be read."));
}
}
MainWindow::~MainWindow()
{
}
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
this->label = new QLabel();
this->setCentralWidget(label);
QString filePath("crash.txt");
QFile f(filePath);
if(f.open(QFile::ReadOnly)) {
QTextStream s(&f);
this->label->setText(s.readAll()); // Crash
} else {
this->label->setText(tr("File ") + filePath + tr(" could not be read."));
}
}
MainWindow::~MainWindow()
{
}
To copy to clipboard, switch view to plain text mode
Just calling s.readAll() works fine.
I attached the file that causes the crash. Again everything works, if i delete the tab.
Bookmarks