TextEdit with Word-Files?



  • Hello,

    i have a new question. I have done my FileBrowser so far to see the Files. But now i want to select them and get them into the TextEdit From my Gui..The other problem is, that i just want some lines of the files in the TextEdit (if its possible). To show you whats my Problem is, i made a Screenshot.

    !http://fs2.directupload.net/images/150205/rbsl4alf.png!

    Here my Code:

    @#include "taskplaner.h"
    #include "ui_taskplaner.h"
    #include <QListWidgetItem>
    #include <QFileDialog>
    #include <QFile>
    #include <QMessageBox>
    #include <QTextStream>
    #include <QtCore>
    #include <QtGui>

    Taskplaner::Taskplaner(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::Taskplaner)
    {
    ui->setupUi(this);

    QString sPath = "P:/";
    dirmodel = new QFileSystemModel(this);
    dirmodel->setFilter(QDir::NoDotAndDotDot | QDir::AllDirs);
    dirmodel->setRootPath(sPath);
    
    ui->treeView->setModel(dirmodel);
    
    filemodel = new QFileSystemModel(this);
    filemodel->setFilter(QDir::NoDotAndDotDot | QDir::Files);
    filemodel->setRootPath(sPath);
    
    ui->listView->setModel(filemodel);
    

    }

    Taskplaner::~Taskplaner()
    {
    delete ui;
    }

    void Taskplaner::on_treeView_clicked(const QModelIndex &index)
    {
    QString sPath = dirmodel->fileInfo(index).absoluteFilePath();
    ui->listView->setRootIndex(filemodel->setRootPath(sPath));
    }

    void Taskplaner::on_actionSave_triggered()
    {
    QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), QString(),
    tr("Text Files (.txt);;Word Files 97-2003 (.doc);; Word Files 2007-2013 (*.docx)"));

    if(!fileName.isEmpty()) {
        QFile file&#40;fileName&#41;;
        if(!file.open(QIODevice::WriteOnly&#41;) {
            QMessageBox msgBox;
            msgBox.setText("error occurred");
        } else {
            QTextStream stream(&file);
            stream << ui->textEdit->toPlainText();
            stream.flush();
            file.close();
        }
    }
    

    }@



  • So, you want to display word files inside your application? There are no Qt components that can display that directly. You will need 3rd party libraries or use some embedding technology to embed a component inside your own application (like MS word itself).



  • Hm okay. I have to improvise so. Is it possible to convert the word files into .txt files in Qt?

    Thanks Adre!

    Edit

    basically i should ask, is it possible to open items from a listview in a textedit from Qt? Forget about the word files. Just talk about the Textfile. The word file maybe will be my stage two of the project because first of all i have to get the basics i think..


  • Lifetime Qt Champion

    Hi,

    Technically all you have to do is open them using QFile, read them and call setText with the content of the QFile. However, if you are building a file viewer you should first detect what type of file you have at hand use the appropriate "viewer".


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.