Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. TextEdit with Word-Files?
Forum Updated to NodeBB v4.3 + New Features

TextEdit with Word-Files?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kopfii
    wrote on last edited by
    #1

    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();
        }
    }
    

    }@

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      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).

      1 Reply Last reply
      0
      • K Offline
        K Offline
        Kopfii
        wrote on last edited by
        #3

        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..

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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".

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved