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. Open a Particular text document in TextEdit box
QtWS25 Last Chance

Open a Particular text document in TextEdit box

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 3 Posters 765 Views
  • 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.
  • W Offline
    W Offline
    Widdershins_NH
    wrote on 29 Dec 2019, 16:38 last edited by
    #1

    I've working in an application where there is a multiple windows.In 2nd window there is text edit box.
    when i jump from 1st window to the 2nd i want the textedit to open a text document from a certain directory.How can i do this?
    I am new to Qt and devolopment.So,a less complicated method will be appreciated.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 29 Dec 2019, 16:49 last edited by
      #2

      Hi,

      Can you explain the workflow more precisely ? You likely don't want to have the text reloaded each time you change to the second window, yes ?
      How do you get to that second window ?

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

      W 1 Reply Last reply 29 Dec 2019, 18:38
      2
      • S SGaist
        29 Dec 2019, 16:49

        Hi,

        Can you explain the workflow more precisely ? You likely don't want to have the text reloaded each time you change to the second window, yes ?
        How do you get to that second window ?

        W Offline
        W Offline
        Widdershins_NH
        wrote on 29 Dec 2019, 18:38 last edited by
        #3

        @SGaist,it's a diary app, the first window is a welcome page.a push button should make the jump to the 2nd page which is the writing page.
        Before jump it will get the system date and check if there is a text file named after it,if there is it will open it in the textedit box and if there is not it will create a text document and open it in the textedit

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 29 Dec 2019, 22:09 last edited by
          #4

          Then the file handling part should happen before showing the other widget.

          You should also think about the saving part.

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

          W 1 Reply Last reply 30 Dec 2019, 09:35
          0
          • S SGaist
            29 Dec 2019, 22:09

            Then the file handling part should happen before showing the other widget.

            You should also think about the saving part.

            W Offline
            W Offline
            Widdershins_NH
            wrote on 30 Dec 2019, 09:35 last edited by
            #5

            @SGaist I've done all those part,I'm stuck in the part where I connect the text document with the TextEdit Box.If anyone can show me me an example it'll be great.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 30 Dec 2019, 18:37 last edited by
              #6

              What do you mean by connect ?

              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
              1
              • M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 30 Dec 2019, 18:57 last edited by
                #7

                Hi
                do you mean to load the text document ?

                 QFile file("FileName.txt");
                
                    if (file.open(QIODevice::ReadOnly)) {
                        QTextStream stream(&file);
                        edit->setPlainText( stream.readAll() );
                    }
                
                W 1 Reply Last reply 30 Dec 2019, 22:57
                0
                • M mrjj
                  30 Dec 2019, 18:57

                  Hi
                  do you mean to load the text document ?

                   QFile file("FileName.txt");
                  
                      if (file.open(QIODevice::ReadOnly)) {
                          QTextStream stream(&file);
                          edit->setPlainText( stream.readAll() );
                      }
                  
                  W Offline
                  W Offline
                  Widdershins_NH
                  wrote on 30 Dec 2019, 22:57 last edited by
                  #8

                  @mrjj The Text document will already exist.When i click a push button it should open the file and show the texts in the TextEdit box in the next page also the textedit box should work as a notepad for the text file,which means i can keep editing the text file and save.
                  I've tired your example,it's not showing anything :(

                  M 1 Reply Last reply 31 Dec 2019, 08:41
                  0
                  • W Widdershins_NH
                    30 Dec 2019, 22:57

                    @mrjj The Text document will already exist.When i click a push button it should open the file and show the texts in the TextEdit box in the next page also the textedit box should work as a notepad for the text file,which means i can keep editing the text file and save.
                    I've tired your example,it's not showing anything :(

                    M Offline
                    M Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 31 Dec 2019, 08:41 last edited by mrjj
                    #9

                    @Widdershins_NH

                    Hi
                    If it shows nothing in your textEdit then maybe the path is not correct ?

                    add a check and see.

                    QFile file("FileName.txt");
                        if (file.open(QIODevice::ReadOnly)) {
                            QTextStream stream(&file);
                            edit->setPlainText( stream.readAll() );
                        } else
                            QMessageBox::warning(this, "title", "file open error:" + file.errorString() );
                    
                    
                    W 1 Reply Last reply 31 Dec 2019, 15:13
                    2
                    • M mrjj
                      31 Dec 2019, 08:41

                      @Widdershins_NH

                      Hi
                      If it shows nothing in your textEdit then maybe the path is not correct ?

                      add a check and see.

                      QFile file("FileName.txt");
                          if (file.open(QIODevice::ReadOnly)) {
                              QTextStream stream(&file);
                              edit->setPlainText( stream.readAll() );
                          } else
                              QMessageBox::warning(this, "title", "file open error:" + file.errorString() );
                      
                      
                      W Offline
                      W Offline
                      Widdershins_NH
                      wrote on 31 Dec 2019, 15:13 last edited by
                      #10
                      This post is deleted!
                      1 Reply Last reply
                      0

                      1/10

                      29 Dec 2019, 16:38

                      • Login

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