I am trying to use QProcess to call 7z.exe and unzip all *.zip and *.7z files in a root directory and subdirectories, but it works only in the root directory.
It looks like it also does not have a problem finding the right path to the next archive, but it did not unzip the file.
Output:
QProcess::start: Process is already running
Can someone help me with this problem?
My code:
mainwindows.h:
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(&unzip,&QProcess::readyReadStandardOutput,this,&MainWindow::readyReadStandardOutput);
connect(&unzip,&QProcess::stateChanged,this,&MainWindow::statusChanged);
connect(ui->startButton,&QPushButton::clicked,this,&MainWindow::startClicked);
connect(&unzip,&QProcess::errorOccurred,this,&MainWindow::processError);
connect(&unzip, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),this,&MainWindow::processFinished);
connect(ui->selectPath,&QPushButton::clicked,this,&MainWindow::selectPathClicked);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::statusChanged(QProcess::ProcessState state){
switch (state) {
case QProcess::NotRunning:
ui->startButton->setText("START");
this->updateUi(true);
break;
case QProcess::Running:
case QProcess::Starting:
ui->startButton->setText("STOP");
this->updateUi(false);
}
}
void MainWindow::updateUi(bool enable)
{
ui->pathEdit->setEnabled(enable);
}
void MainWindow::startClicked()
{
qDebug()<<"Started";
QStringList arguments;
QString path=ui->pathEdit->text();
arguments<<"x"<<path+QDir::separator()+"*.zip"<<"-o"+path+QDir::separator()+"*";
switch (unzip.state()) {
case QProcess::NotRunning:
unzip.setWorkingDirectory(QCoreApplication::applicationDirPath());
unzip.start("7z.exe",arguments);
break;
case QProcess::Running:
case QProcess::Starting:
unzip.kill();
break;
}
}
void MainWindow::readyReadStandardOutput(){
ui->logTextEdit->appendPlainText(unzip.readAllStandardOutput());
}
void MainWindow::processError(QProcess::ProcessError error)
{
QMessageBox::critical(this,"Unzip warpper",tr("Error %1 has occured").arg(error));
}
void MainWindow::processFinished(int exitCode, QProcess::ExitStatus exit)
{
switch (exit) {
case QProcess::CrashExit:
QMessageBox::critical(this,"Unzip warpper",tr("Unzip process has crashed"));
break;
case QProcess::NormalExit:
break;
}
if(ui->checkRecursive->isChecked()){
QString path=ui->pathEdit->text();
QDirIterator it(path, QStringList() << "*.zip" << ".7z" ,QDir::Files, QDirIterator::Subdirectories);
while(it.hasNext()){
QString path=it.next();
qDebug()<<path;
qDebug()<<exitCode;
QStringList arguments;
arguments<<"x"<<path+QDir::separator()+"*.zip"<<"-o"+path+QDir::separator()+"*";
unzip.start("7z.exe",arguments);
}
}
}
void MainWindow::selectPathClicked()
{
QString directory = QFileDialog::getExistingDirectory(this,
tr("Select Direcory to unzip"), "");
if(!directory.isEmpty()){
ui->pathEdit->setText(directory);
}
}
void MainWindow::on_actionQuit_triggered()
{
unzip.kill();
QApplication::quit();
}
Related
I'm currently working on a Qt Widget (using Qt 6.3) that plays audio and shows a progressbar. But I'm struggling to find a way to connect the audio progress value with the progress bar status.
Here's my code:
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
mMediaPlayer = new QMediaPlayer(this);
audio_output = new QAudioOutput(this);
//this is the part I need help with
connect(mMediaPlayer, SIGNAL(positionChanged(qint64)), this, SLOT(positionChanged(qint64)));
void MainWindow::on_Button_open_media_clicked()
{
QString file_name = QFileDialog::getOpenFileName(this, "Open");
if(file_name.isEmpty()){
return;
}
mMediaPlayer->setSource(QUrl::fromLocalFile(file_name));
mMediaPlayer->setAudioOutput(audio_output);
audio_output->setVolume(ui->volume_slider->value());
on_play_button_clicked();
}
void MainWindow::on_stop_button_clicked()
{
mMediaPlayer->stop();
}
void MainWindow::on_pause_button_clicked()
{
mMediaPlayer->pause();
}
void MainWindow::on_play_button_clicked()
{
audio_output->setVolume(100);
mMediaPlayer->play();
}
void MainWindow::on_mute_button_clicked()
{
if(ui->mute_button->text() == "Mute"){
audio_output->setMuted(true);
ui->mute_button->setText("Unmute");
}
else{
audio_output->setMuted(false);
ui->mute_button->setText("Mute");
}
}
void MainWindow::on_volume_slider_valueChanged(int value)
{
audio_output->setVolume(value);
}
}
I couldn't find a way to do it using the documentation. It might be simple, but I need help.
Any help is gladly appreciated.
I Keep getting this error when i try and build this app. Help?
The inferior stopped because it received a signal from the operating system.
Signal name: SIGSEGV
Signal meaning: Segmentation fault
Here is the code for the mainwindow.cpp file
It says the error is on line 122 which is the
copyAct->setEnabled(false);
this is about half way down.
#include "mainwindow.h"
#include <QtGui>
MainWindow::MainWindow(QWidget *parent)
{
textEdit = new QPlainTextEdit;
setCentralWidget(textEdit);
createActions();
createMenus();
createToolBars();
createStatusBar();
readSettings();
connect(textEdit->document(), SIGNAL(contentsChanged()),this, SLOT(documentWasModified()));
setCurrentFile("");
setUnifiedTitleAndToolBarOnMac(true);
}
void MainWindow::closeEvent(QCloseEvent *event)
{
if(maybeSave()){
writeSettings();
event->accept();
}
else{
event->ignore();
}
}
void MainWindow::newFile()
{
if(maybeSave()){
textEdit->clear();
setCurrentFile("");
}
}
void MainWindow::open()
{
if(maybeSave()){
QString fileName = QFileDialog::getOpenFileName(this);
if(!fileName.isEmpty())
loadFile(fileName);
}
}
bool MainWindow::save()
{
if(curFile.isEmpty()){
return saveAs();
}
else{
return saveFile(curFile);
}
}
bool MainWindow::saveAs()
{
QString fileName = QFileDialog::getSaveFileName(this);
if(fileName.isEmpty())
return false;
return saveFile(fileName);
}
void MainWindow::about()
{
QMessageBox::about(this, tr("About Application"),
tr("Whatever you want it to say here!"));
}
void MainWindow::documentWasModified()
{
setWindowModified(textEdit->document()->isModified());
}
void MainWindow::createActions()
{
newAct = new QAction(tr("&New"), this);
newAct->setShortcuts(QKeySequence::New);
newAct->setStatusTip(tr("Create a new file"));
connect(newAct, SIGNAL(triggered()), this, SLOT(newFile()));
openAct = new QAction(tr("&Open..."), this);
openAct->setShortcuts(QKeySequence::Open);
openAct->setStatusTip(tr("Open an existing file"));
connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
saveAct = new QAction(tr("&Save"), this);
saveAct->setShortcuts(QKeySequence::Save);
saveAct->setStatusTip(tr("Save an open file"));
connect(saveAct, SIGNAL(triggered()), this, SLOT(save()));
saveAsAct = new QAction(tr("&Save As"), this);
saveAsAct->setShortcuts(QKeySequence::SaveAs);
saveAsAct->setStatusTip(tr("Save a new file"));
connect(openAct, SIGNAL(triggered()), this, SLOT(saveAs()));
exitAct = new QAction(tr("&Exit"), this);
exitAct->setShortcuts(QKeySequence::Close);
exitAct->setStatusTip(tr("Exit the application"));
connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
cutAct = new QAction(tr("&Cut"), this);
cutAct->setShortcuts(QKeySequence::Cut);
cutAct->setStatusTip(tr("Cut the selected text"));
pasteAct = new QAction(tr("&Paste"), this);
pasteAct->setShortcuts(QKeySequence::Paste);
pasteAct->setStatusTip(tr("Paste selected text"));
connect(pasteAct, SIGNAL(triggered()), this, SLOT(setEnabled(bool)));
aboutAct = new QAction(tr("&About"), this);
aboutAct->setShortcuts(QKeySequence::UnknownKey);
aboutAct->setStatusTip(tr("About the application"));
connect(aboutAct, SIGNAL(triggered()), this, SLOT(show()));
cutAct->setEnabled(false);
copyAct->setEnabled(false);
connect(textEdit, SIGNAL(copyAvailable(bool)), cutAct, SLOT(setEnabled(bool)));
connect(textEdit, SIGNAL(copyAvailable(bool)), copyAct, SLOT(setEnabled(bool)));
}
void MainWindow::createMenus()
{
fileMenu = menuBar()->addMenu(tr("&File"));
fileMenu->addAction(newAct);
fileMenu->addAction(openAct);
fileMenu->addAction(saveAct);
fileMenu->addAction(saveAsAct);
fileMenu->addSeparator();
fileMenu->addAction(exitAct);
editMenu = menuBar()->addMenu(tr("&Edit"));
editMenu->addAction(cutAct);
editMenu->addAction(copyAct);
editMenu->addAction(pasteAct);
menuBar()->addSeparator();
helpMenu = menuBar()->addMenu(tr("&Help"));
helpMenu->addAction(aboutAct);
}
void MainWindow::createToolBars()
{
fileToolBar = addToolBar(tr("File"));
fileToolBar->addAction(newAct);
fileToolBar->addAction(openAct);
fileToolBar->addAction(saveAct);
editToolBar = addToolBar(tr("Edit"));
editToolBar->addAction(cutAct);
editToolBar->addAction(copyAct);
editToolBar->addAction(pasteAct);
}
void MainWindow::createStatusBar()
{
statusBar()->showMessage(tr("Ready"));
}
void MainWindow::readSettings()
{
QSettings settings("Zach Starnes", "Zach's Text Editor");
QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
QSize size = settings.value("size", QSize(400, 400)).toSize();
resize(size);
move(pos);
}
void MainWindow::writeSettings()
{
QSettings settings("Zach Starnes", "Zach's Text Editor");
settings.setValue("pos", pos());
settings.setValue("size", size());
}
bool MainWindow::maybeSave()
{
if (textEdit->document()->isModified()) {
QMessageBox::StandardButton ret;
ret = QMessageBox::warning(this, tr("Application"),
tr("The document has been modified.\n"
"Do you want to save your changes?"),
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
if (ret == QMessageBox::Save)
return save();
else if (ret == QMessageBox::Cancel)
return false;
}
return true;
}
void MainWindow::loadFile(const QString &fileName)
{
QFile file(fileName);
if (!file.open(QFile::ReadOnly | QFile::Text)) {
QMessageBox::warning(this, tr("Application"),
tr("Cannot read file %1:\n%2.")
.arg(fileName)
.arg(file.errorString()));
return;
}
QTextStream in(&file);
#ifndef QT_NO_CURSOR
QApplication::setOverrideCursor(Qt::WaitCursor);
#endif
textEdit->setPlainText(in.readAll());
#ifndef QT_NO_CURSOR
QApplication::restoreOverrideCursor();
#endif
setCurrentFile(fileName);
statusBar()->showMessage(tr("File loaded"), 2000);
}
bool MainWindow::saveFile(const QString &fileName)
{
QFile file(fileName);
if (!file.open(QFile::WriteOnly | QFile::Text)) {
QMessageBox::warning(this, tr("Application"),
tr("Cannot write file %1:\n%2.")
.arg(fileName)
.arg(file.errorString()));
return false;
}
QTextStream out(&file);
#ifndef QT_NO_CURSOR
QApplication::setOverrideCursor(Qt::WaitCursor);
#endif
out << textEdit->toPlainText();
#ifndef QT_NO_CURSOR
QApplication::restoreOverrideCursor();
#endif
setCurrentFile(fileName);
statusBar()->showMessage(tr("File saved"), 2000);
return true;
}
void MainWindow::setCurrentFile(const QString &fileName)
{
curFile = fileName;
textEdit->document()->setModified(false);
setWindowModified(false);
QString shownName = curFile;
if (curFile.isEmpty())
shownName = "untitled.txt";
setWindowFilePath(shownName);
}
QString MainWindow::strippedName(const QString &fullFileName)
{
return QFileInfo(fullFileName).fileName();
}
Looks like for every other action you have (which I assume are member data pointers), you've allocated some memory for:
aboutAct = new QAction(tr("&About"), this);
copyAct seems to be the only action you haven't allocated anything for, and therefore you are dereferencing an invalid pointer.
copyAct->setEnabled(false); // segfault :(
You are missing something like this, I assume:
copyAct = new QAction(tr("&Copy"), this);
I hope this isn't your entire cpp file either, as I don't see a destructor nor any delete's to match all those new commands.
I wanted to open QFileDialog for a specific path like //DC1/C$/Users/ but when QFileDialog opens it goes to a default path. When QFileDialog opens, I can change directory to the UNC path but I wanted to open this path as default. How can I do that? In the following code, g_absolutePath has been initialized with //DC1/C$/Users/ but it doesn't work.
#include "uploadfm.h"
#include "ui_uploadfm.h"
#include "mainwindow.h"
UploadFM::UploadFM(QWidget *parent) : QMainWindow(parent), ui(new Ui::UploadFM)
{
ui->setupUi(this);
QWidget::setFixedSize(600, 175);
}
UploadFM::~UploadFM()
{
delete ui;
}
void UploadFM::on_pushButtonSource_clicked()
{
QString fileName = QFileDialog::getOpenFileName(this, "Choose File", g_absolutePath);
if(fileName.isEmpty())
return;
ui->lineEditSourcePath->setText(fileName);
}
void UploadFM::on_pushButtonDestination_clicked()
{
QString fileName = QFileDialog::getExistingDirectory(this, "Choose Folder", g_absolutePath);
if(fileName.isEmpty())
return;
ui->lineEditDestinationPath->setText(fileName);
}
void UploadFM::on_pushButtonUpload_clicked()
{
QString l_sourceFileName = ui->lineEditSourcePath->text();
QString l_destinationFileName = ui->lineEditDestinationPath->text();
if(l_sourceFileName.isEmpty() || l_destinationFileName.isEmpty())
return;
QFile file(l_sourceFileName);
if(file.copy(l_destinationFileName))
{
statusBar()->showMessage("Upload has been Successful ... ");
}
else
{
statusBar()->showMessage("Upload has failed ...");
}
}
The Qt Documentation documents how to do this :
void UploadFM::on_pushButtonDestination_clicked()
{
const QString defaultPath = "//DC1/blabla...";
QString fileName = QFileDialog::getExistingDirectory(this, "Choose Folder", g_absolutePath, defaultPath);
...
}
I'm trying to add a save as feature to a simple text editor I'm making with C++ and QT. I'm attempting to close the current tab when you save your file and open a new tab with the same index and has the name of the new file as the tab title. This is my code:
QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"), "", tr("All Files (*)"));
if (fileName.isEmpty())
return;
else
{
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly))
{
QMessageBox::information(this, tr("Unable to open file"),
file.errorString());
return;
}
QTextStream out (&file);`
out << ui->plainTextEdit->toPlainText();
QFileInfo FileData(file);
int currentTab = ui->tabWidget->currentIndex();
ui->tabWidget->removeTab(currentTab);
QTextStream InputData(&file);
ui->tabWidget->insertTab(currentTab, new Form(), FileData.fileName());
ui->tabWidget->setCurrentIndex(currentTab);
ui->plainTextEdit->setPlainText(InputData.readAll());
file.flush();
file.close();
}
When I try to save the new file, it saves the file to the selected location and replaces the current tab with the file name, but it doesn't write the file to the text window. Any help would be great.
Here is my demo code and it seems to work:
form.cpp which has a plainTextEdit
#include "form.h"
#include "ui_form.h"
Form::Form(QWidget *parent) :
QWidget(parent),
ui(new Ui::Form)
{
ui->setupUi(this);
}
Form::~Form()
{
delete ui;
}
QString Form::GetText()
{
return ui->plainTextEdit->toPlainText();
}
void Form::SetText(QString text)
{
ui->plainTextEdit->setPlainText(text);
}
And the mainwindow.cpp which contains a QTabWidget
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "form.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
ui->tabWidget->insertTab(0, new Form(), "My File");
ui->tabWidget->setCurrentIndex(0);
}
void MainWindow::on_pushButton_2_clicked()
{
int currentIndex = ui->tabWidget->currentIndex();
//Save the text to a file or a variable...
QString content = static_cast<Form*>(ui->tabWidget->widget(currentIndex))->GetText();
ui->tabWidget->removeTab(currentIndex);
ui->tabWidget->insertTab(currentIndex, new Form(), "Saved File");//new name
static_cast<Form*>(ui->tabWidget->widget(currentIndex))->SetText(content);
ui->tabWidget->setCurrentIndex(currentIndex);
}
It is working for me, please try.
Thank You.
I Keep getting this error when i try and build this app. Help?
The inferior stopped because it received a signal from the operating system.
Signal name: SIGSEGV
Signal meaning: Segmentation fault
Here is the code for the mainwindow.cpp file
It says the error is on line 122 which is the
copyAct->setEnabled(false);
this is about half way down.
#include "mainwindow.h"
#include <QtGui>
MainWindow::MainWindow(QWidget *parent)
{
textEdit = new QPlainTextEdit;
setCentralWidget(textEdit);
createActions();
createMenus();
createToolBars();
createStatusBar();
readSettings();
connect(textEdit->document(), SIGNAL(contentsChanged()),this, SLOT(documentWasModified()));
setCurrentFile("");
setUnifiedTitleAndToolBarOnMac(true);
}
void MainWindow::closeEvent(QCloseEvent *event)
{
if(maybeSave()){
writeSettings();
event->accept();
}
else{
event->ignore();
}
}
void MainWindow::newFile()
{
if(maybeSave()){
textEdit->clear();
setCurrentFile("");
}
}
void MainWindow::open()
{
if(maybeSave()){
QString fileName = QFileDialog::getOpenFileName(this);
if(!fileName.isEmpty())
loadFile(fileName);
}
}
bool MainWindow::save()
{
if(curFile.isEmpty()){
return saveAs();
}
else{
return saveFile(curFile);
}
}
bool MainWindow::saveAs()
{
QString fileName = QFileDialog::getSaveFileName(this);
if(fileName.isEmpty())
return false;
return saveFile(fileName);
}
void MainWindow::about()
{
QMessageBox::about(this, tr("About Application"),
tr("Whatever you want it to say here!"));
}
void MainWindow::documentWasModified()
{
setWindowModified(textEdit->document()->isModified());
}
void MainWindow::createActions()
{
newAct = new QAction(tr("&New"), this);
newAct->setShortcuts(QKeySequence::New);
newAct->setStatusTip(tr("Create a new file"));
connect(newAct, SIGNAL(triggered()), this, SLOT(newFile()));
openAct = new QAction(tr("&Open..."), this);
openAct->setShortcuts(QKeySequence::Open);
openAct->setStatusTip(tr("Open an existing file"));
connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
saveAct = new QAction(tr("&Save"), this);
saveAct->setShortcuts(QKeySequence::Save);
saveAct->setStatusTip(tr("Save an open file"));
connect(saveAct, SIGNAL(triggered()), this, SLOT(save()));
saveAsAct = new QAction(tr("&Save As"), this);
saveAsAct->setShortcuts(QKeySequence::SaveAs);
saveAsAct->setStatusTip(tr("Save a new file"));
connect(openAct, SIGNAL(triggered()), this, SLOT(saveAs()));
exitAct = new QAction(tr("&Exit"), this);
exitAct->setShortcuts(QKeySequence::Close);
exitAct->setStatusTip(tr("Exit the application"));
connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
cutAct = new QAction(tr("&Cut"), this);
cutAct->setShortcuts(QKeySequence::Cut);
cutAct->setStatusTip(tr("Cut the selected text"));
pasteAct = new QAction(tr("&Paste"), this);
pasteAct->setShortcuts(QKeySequence::Paste);
pasteAct->setStatusTip(tr("Paste selected text"));
connect(pasteAct, SIGNAL(triggered()), this, SLOT(setEnabled(bool)));
aboutAct = new QAction(tr("&About"), this);
aboutAct->setShortcuts(QKeySequence::UnknownKey);
aboutAct->setStatusTip(tr("About the application"));
connect(aboutAct, SIGNAL(triggered()), this, SLOT(show()));
cutAct->setEnabled(false);
copyAct->setEnabled(false);
connect(textEdit, SIGNAL(copyAvailable(bool)), cutAct, SLOT(setEnabled(bool)));
connect(textEdit, SIGNAL(copyAvailable(bool)), copyAct, SLOT(setEnabled(bool)));
}
void MainWindow::createMenus()
{
fileMenu = menuBar()->addMenu(tr("&File"));
fileMenu->addAction(newAct);
fileMenu->addAction(openAct);
fileMenu->addAction(saveAct);
fileMenu->addAction(saveAsAct);
fileMenu->addSeparator();
fileMenu->addAction(exitAct);
editMenu = menuBar()->addMenu(tr("&Edit"));
editMenu->addAction(cutAct);
editMenu->addAction(copyAct);
editMenu->addAction(pasteAct);
menuBar()->addSeparator();
helpMenu = menuBar()->addMenu(tr("&Help"));
helpMenu->addAction(aboutAct);
}
void MainWindow::createToolBars()
{
fileToolBar = addToolBar(tr("File"));
fileToolBar->addAction(newAct);
fileToolBar->addAction(openAct);
fileToolBar->addAction(saveAct);
editToolBar = addToolBar(tr("Edit"));
editToolBar->addAction(cutAct);
editToolBar->addAction(copyAct);
editToolBar->addAction(pasteAct);
}
void MainWindow::createStatusBar()
{
statusBar()->showMessage(tr("Ready"));
}
void MainWindow::readSettings()
{
QSettings settings("Zach Starnes", "Zach's Text Editor");
QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
QSize size = settings.value("size", QSize(400, 400)).toSize();
resize(size);
move(pos);
}
void MainWindow::writeSettings()
{
QSettings settings("Zach Starnes", "Zach's Text Editor");
settings.setValue("pos", pos());
settings.setValue("size", size());
}
bool MainWindow::maybeSave()
{
if (textEdit->document()->isModified()) {
QMessageBox::StandardButton ret;
ret = QMessageBox::warning(this, tr("Application"),
tr("The document has been modified.\n"
"Do you want to save your changes?"),
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
if (ret == QMessageBox::Save)
return save();
else if (ret == QMessageBox::Cancel)
return false;
}
return true;
}
void MainWindow::loadFile(const QString &fileName)
{
QFile file(fileName);
if (!file.open(QFile::ReadOnly | QFile::Text)) {
QMessageBox::warning(this, tr("Application"),
tr("Cannot read file %1:\n%2.")
.arg(fileName)
.arg(file.errorString()));
return;
}
QTextStream in(&file);
#ifndef QT_NO_CURSOR
QApplication::setOverrideCursor(Qt::WaitCursor);
#endif
textEdit->setPlainText(in.readAll());
#ifndef QT_NO_CURSOR
QApplication::restoreOverrideCursor();
#endif
setCurrentFile(fileName);
statusBar()->showMessage(tr("File loaded"), 2000);
}
bool MainWindow::saveFile(const QString &fileName)
{
QFile file(fileName);
if (!file.open(QFile::WriteOnly | QFile::Text)) {
QMessageBox::warning(this, tr("Application"),
tr("Cannot write file %1:\n%2.")
.arg(fileName)
.arg(file.errorString()));
return false;
}
QTextStream out(&file);
#ifndef QT_NO_CURSOR
QApplication::setOverrideCursor(Qt::WaitCursor);
#endif
out << textEdit->toPlainText();
#ifndef QT_NO_CURSOR
QApplication::restoreOverrideCursor();
#endif
setCurrentFile(fileName);
statusBar()->showMessage(tr("File saved"), 2000);
return true;
}
void MainWindow::setCurrentFile(const QString &fileName)
{
curFile = fileName;
textEdit->document()->setModified(false);
setWindowModified(false);
QString shownName = curFile;
if (curFile.isEmpty())
shownName = "untitled.txt";
setWindowFilePath(shownName);
}
QString MainWindow::strippedName(const QString &fullFileName)
{
return QFileInfo(fullFileName).fileName();
}
Looks like for every other action you have (which I assume are member data pointers), you've allocated some memory for:
aboutAct = new QAction(tr("&About"), this);
copyAct seems to be the only action you haven't allocated anything for, and therefore you are dereferencing an invalid pointer.
copyAct->setEnabled(false); // segfault :(
You are missing something like this, I assume:
copyAct = new QAction(tr("&Copy"), this);
I hope this isn't your entire cpp file either, as I don't see a destructor nor any delete's to match all those new commands.