но было бы лучше, если кто-нибудь объяснил
private slots:void buttonClicked();
connect(button,SIGNAL(clicked()),this,SLOT(buttonClicked()));
C++ (Qt)void Widget::on_pushButton_clicked(){ QTextDocumentWriter writer("filename.txt", "plaintext"); writer.write(ui->textEdit->document());}
QStringList lines; QFile file( "C:/1.txt" ); if ( file.open( QFile::ReadOnly ) ) { QTextStream stream( &file ); QString line; while ( !stream.atEnd() ) { line = stream.readLine(); // line of text excluding '\n' lines += line; } file.close(); }
C++ (Qt) QFile file("filename.txt"); if (file.open(QIODevice::ReadOnly)) ui->textEdit->setPlainText(QString::fromUtf8(file.readAll()));
C++ (Qt) QFile file("filename.txt"); if (!file.open(QIODevice::ReadOnly)) return; while (!file.atEnd()) { ui->textEdit->textCursor().insertText(QString::fromUtf8(file.readLine())); }
QFile::remove(C:/1.txt");
#include "widget.h"#include <QApplication>int main(int argc, char *argv[]){ QApplication a(argc, argv); Widget w; w.show(); return a.exec();}
#ifndef WIDGET_H#define WIDGET_H#include <QtWidgets>class Widget : public QWidget{ Q_OBJECTpublic: Widget(QWidget *parent = 0); ~Widget(); QTextEdit * qtext; QPushButton * btn; QVBoxLayout * layout;//public slots:// void SaveToFile(QTextEdit*qt);public slots: void SaveToFile();};#endif // WIDGET_H
#include "widget.h"Widget::Widget(QWidget *parent) : QWidget(parent){ QTextEdit * qtext = new QTextEdit; QPushButton * btn = new QPushButton("&Save"); QVBoxLayout * layout = new QVBoxLayout; //QObject::connect(btn,SIGNAL(clicked()),this,SLOT(SaveToFile(qtext))); QObject::connect(btn,SIGNAL(clicked()),this,SLOT(SaveToFile())); layout->addWidget(qtext); layout->addWidget(btn); setLayout(layout);}Widget::~Widget(){}// void Widget::SaveToFile(QTextEdit * qt)//{// QTextDocumentWriter * writer = new QTextDocumentWriter;// writer->setFormat("odf");// writer->setFileName("C:/Users/Геннадий/Desktop/output.odf");// writer->write(qt->document());// qDebug()<<"it worck";// } void Widget::SaveToFile() { QTextEdit * qtext = new QTextEdit("Text to save"); QTextDocumentWriter * writer = new QTextDocumentWriter; writer->setFormat("odf"); writer->setFileName("C:/Users/Геннадий/Desktop/output.odf"); writer->write(qtext->document()); qDebug()<<"it worck"; }