Ich will dass mein Programm es abcheckt, ob eine neue Datei geöffnet wurde oder eine vorhandene Datei damit er entscheidet ob Save oder Save As.
die header datei:
Code: Alles auswählen
class MainWindow : public QMainWindow, private Ui::mainWindow
{
Q_OBJECT
QLabel* m_WordsLabel;
QLabel* m_LetterLabel;
bool m_DocumentChanged;
QString m_FileName;
public:
MainWindow(QWidget* parent = NULL);
~MainWindow();
protected:
void setupActions();
void setupStatusBar();
public slots:
void newFileAction();
void fileOpenAction();
void undoAction();
void redoAction();
void copyAction();
void cutAction();
void pasteAction();
void textChanged();
void aboutWindow();
bool saveFileAsAction();
};Code: Alles auswählen
void MainWindow::fileOpenAction()
{
QString s = QFileDialog::getOpenFileName ( this, tr("Open File"), tr("HTML"), "html (*.html)");
statusbar->showMessage ( tr("Load File: ") + s, 10000 );
QFile file( s );
if( !file.open( QIODevice::ReadOnly | QIODevice::Text) )
return;
textEdit->setPlainText( QString::fromUtf8( file.readAll() ) );
}Code: Alles auswählen
void MainWindow::newFileAction()
{
if( saveFileAsAction() )
{
textEdit->clear();
}
statusbar->showMessage ( tr("New File"), 10000 );
}Code: Alles auswählen
bool MainWindow::saveFileAsAction()
{
QTextDocument* document = textEdit->document();
if( !document )
return false;
if( document->isEmpty() )
return false;
QString fileName = QFileDialog::getSaveFileName( this, tr("Save As.."), QDir::currentPath(), "html (*.html)" );
if( fileName.isEmpty() )
return false;
statusbar->showMessage ( tr("Save File: ") + fileName, 10000 );
QFile file( fileName );
if( !file.open( QIODevice::WriteOnly | QIODevice::Text ) )
return false;
file.write( textEdit->document()->toPlainText().toUtf8() );
return true;
}danke