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. How to use QTextEdit
Forum Updated to NodeBB v4.3 + New Features

How to use QTextEdit

Scheduled Pinned Locked Moved Unsolved General and Desktop
22 Posts 5 Posters 2.7k Views 2 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.
  • Gojir4G Gojir4

    @jenya7 Of course. It is only visible in MainWindow.
    You need to add a method (or slot) in your MainWindow allowing to access the control, or to set the text

    void MainWindow::setTerminalText(const QString &txt){
        ui->textEditTerminalRx->setText(txt);
    }
    
    J Offline
    J Offline
    jenya7
    wrote on last edited by jenya7
    #13

    @Gojir4 said in How to use QTextEdit:

    @jenya7 Of course. It is only visible in MainWindow.
    You need to add a method (or slot) in your MainWindow allowing to access the control, or to set the text

    void MainWindow::setTerminalText(const QString &txt){
        ui->textEditTerminalRx->setText(txt);
    }
    

    Can I invoke this method from another file? say in sys.cpp I have

    void SYS_SomeFunc ()
    {
        DoSomeTask();
    
         DisplayTextIn_textEditTerminalRx();
    }
    

    Well...It demands some further explanation. I want to provide to a user some indication what’s going on in the project’s running tasks. So instead of flooding him with numerous pop-up QMessageBox I want to print out the messages at my textEditTerminalRx.

    JonBJ 1 Reply Last reply
    0
    • Gojir4G Gojir4

      @jenya7 Of course. It is only visible in MainWindow.
      You need to add a method (or slot) in your MainWindow allowing to access the control, or to set the text

      void MainWindow::setTerminalText(const QString &txt){
          ui->textEditTerminalRx->setText(txt);
      }
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #14

      @Gojir4 said in How to use QTextEdit:

      @jenya7 Of course. It is only visible in MainWindow.
      You need to add a method (or slot) in your MainWindow allowing to access the control, or to set the text
      void MainWindow::setTerminalText(const QString &txt){
      ui->textEditTerminalRx->setText(txt);
      }

      OOI, how does this help? How does a different class/module/form get any access to the MainWindow instance to call that method, any more than to the ui?

      Gojir4G 1 Reply Last reply
      0
      • J jenya7

        @Gojir4 said in How to use QTextEdit:

        @jenya7 Of course. It is only visible in MainWindow.
        You need to add a method (or slot) in your MainWindow allowing to access the control, or to set the text

        void MainWindow::setTerminalText(const QString &txt){
            ui->textEditTerminalRx->setText(txt);
        }
        

        Can I invoke this method from another file? say in sys.cpp I have

        void SYS_SomeFunc ()
        {
            DoSomeTask();
        
             DisplayTextIn_textEditTerminalRx();
        }
        

        Well...It demands some further explanation. I want to provide to a user some indication what’s going on in the project’s running tasks. So instead of flooding him with numerous pop-up QMessageBox I want to print out the messages at my textEditTerminalRx.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #15

        @jenya7 said in How to use QTextEdit:

        Well...It demands some further explanation. I want to provide to a user some indication what’s going on in the project’s running tasks. So instead of flooding him with numerous pop-up QMessageBox I want to print out the messages at my textEditTerminalRx.

        You either need to decide to gain access to the main window's text edit so that you can set its text directly, or (perhaps more suitable for your use case) you could have it raise a signal when stuff is"going on", and the main window could place a slot on that signal so that it updates the text edit.

        J 1 Reply Last reply
        1
        • JonBJ JonB

          @jenya7 said in How to use QTextEdit:

          Well...It demands some further explanation. I want to provide to a user some indication what’s going on in the project’s running tasks. So instead of flooding him with numerous pop-up QMessageBox I want to print out the messages at my textEditTerminalRx.

          You either need to decide to gain access to the main window's text edit so that you can set its text directly, or (perhaps more suitable for your use case) you could have it raise a signal when stuff is"going on", and the main window could place a slot on that signal so that it updates the text edit.

          J Offline
          J Offline
          jenya7
          wrote on last edited by
          #16

          @JonB said in How to use QTextEdit:

          @jenya7 said in How to use QTextEdit:

          Well...It demands some further explanation. I want to provide to a user some indication what’s going on in the project’s running tasks. So instead of flooding him with numerous pop-up QMessageBox I want to print out the messages at my textEditTerminalRx.

          You either need to decide to gain access to the main window's text edit so that you can set its text directly, or (perhaps more suitable for your use case) you could have it raise a signal when stuff is"going on", and the main window could place a slot on that signal so that it updates the text edit.

          Looks like fun. How do I do that?

          JonBJ 1 Reply Last reply
          0
          • J jenya7

            @JonB said in How to use QTextEdit:

            @jenya7 said in How to use QTextEdit:

            Well...It demands some further explanation. I want to provide to a user some indication what’s going on in the project’s running tasks. So instead of flooding him with numerous pop-up QMessageBox I want to print out the messages at my textEditTerminalRx.

            You either need to decide to gain access to the main window's text edit so that you can set its text directly, or (perhaps more suitable for your use case) you could have it raise a signal when stuff is"going on", and the main window could place a slot on that signal so that it updates the text edit.

            Looks like fun. How do I do that?

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #17

            @jenya7
            You start by reading https://doc.qt.io/qt-5/signalsandslots.html, or similar, which explains Qt's signals & slots. You're going to need that anyway to get anywhere in Qt, so it's not time wasted!

            Then in principle you declare a signal out of your other file where you are "doing stuff which must be reported", include that header file into main window so it knows about the signal, and have main window put a slot on that signal. The slot does the setText(). The signalling class can pass any necessary arguments (e..g what to write, how far it's got...).

            Your "project’s running tasks" sound like you want them to run in a thread, so that they do not block the UI? And they would send these signals from their thread to be acted on in the main window UI thread.

            1 Reply Last reply
            3
            • J Offline
              J Offline
              jenya7
              wrote on last edited by
              #18

              Can I create signals and slots withing a class only? Can I do it in a file like

              my_file.cpp:

              #include ''my_file.h''

              slot my_slot;
              signal my_signal;

              void Func(void)
              {
              }

              //end of file

              mrjjM 1 Reply Last reply
              0
              • J jenya7

                Can I create signals and slots withing a class only? Can I do it in a file like

                my_file.cpp:

                #include ''my_file.h''

                slot my_slot;
                signal my_signal;

                void Func(void)
                {
                }

                //end of file

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #19

                @jenya7
                Hi
                Yes its only with classes.
                And it needs to derive from QObject and have the Q_OBJECT macro and be in a .h file.

                class MyClass : public QObject
                {
                Q_OBJECT
                ....

                1 Reply Last reply
                2
                • J Offline
                  J Offline
                  jenya7
                  wrote on last edited by
                  #20

                  Thank you.

                  1 Reply Last reply
                  0
                  • JonBJ JonB

                    @Gojir4 said in How to use QTextEdit:

                    @jenya7 Of course. It is only visible in MainWindow.
                    You need to add a method (or slot) in your MainWindow allowing to access the control, or to set the text
                    void MainWindow::setTerminalText(const QString &txt){
                    ui->textEditTerminalRx->setText(txt);
                    }

                    OOI, how does this help? How does a different class/module/form get any access to the MainWindow instance to call that method, any more than to the ui?

                    Gojir4G Offline
                    Gojir4G Offline
                    Gojir4
                    wrote on last edited by
                    #21

                    @JonB said in How to use QTextEdit:

                    @Gojir4 said in How to use QTextEdit:

                    @jenya7 Of course. It is only visible in MainWindow.
                    You need to add a method (or slot) in your MainWindow allowing to access the control, or to set the text
                    void MainWindow::setTerminalText(const QString &txt){
                    ui->textEditTerminalRx->setText(txt);
                    }

                    OOI, how does this help? How does a different class/module/form get any access to the MainWindow instance to call that method, any more than to the ui?

                    @JonB said in How to use QTextEdit:

                    You either need to decide to gain access to the main window's text edit so that you can set its text directly, or (perhaps more suitable for your use case) you could have it raise a signal when stuff is"going on", and the main window could place a slot on that signal so that it updates the text edit.

                    :P thanks for this moment of fun

                    JonBJ 1 Reply Last reply
                    0
                    • Gojir4G Gojir4

                      @JonB said in How to use QTextEdit:

                      @Gojir4 said in How to use QTextEdit:

                      @jenya7 Of course. It is only visible in MainWindow.
                      You need to add a method (or slot) in your MainWindow allowing to access the control, or to set the text
                      void MainWindow::setTerminalText(const QString &txt){
                      ui->textEditTerminalRx->setText(txt);
                      }

                      OOI, how does this help? How does a different class/module/form get any access to the MainWindow instance to call that method, any more than to the ui?

                      @JonB said in How to use QTextEdit:

                      You either need to decide to gain access to the main window's text edit so that you can set its text directly, or (perhaps more suitable for your use case) you could have it raise a signal when stuff is"going on", and the main window could place a slot on that signal so that it updates the text edit.

                      :P thanks for this moment of fun

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by
                      #22

                      @Gojir4 said in How to use QTextEdit:

                      :P thanks for this moment of fun

                      ??

                      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