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.6k 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.
  • J jenya7

    I placed QTextEdit on a form.
    I see it in ui->setupUi(this);

    textEditTerminalRx = new QTextEdit(tab_terminal);
    textEditTerminalRx->setObjectName(QString::fromUtf8("textEditTerminalRx"));
    textEditTerminalRx->setGeometry(QRect(80, 100, 521, 91));
    

    How can I set text in textEditTerminalRx? what visibility scope? it's not seen at mainwindow.cpp.

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

    @jenya7
    Whe you design your form with the designer, an ui element is created in your widget's code.

    So calling ui->textEditTerminalRx should give you access to your text widget

    J 1 Reply Last reply
    1
    • JonBJ JonB

      @jenya7
      You used to have

      textEditTerminalRx = new QTextEdit(tab_terminal);
      

      which at least gave it a parent, so it appeared on whatever tab_terminal is. Now that you have simply gone

       QTextEdit txt_edit;
       txt_edit.setText("text");
      

      the text edit won't even appear anywhere, without further code at least.

      But how can I get a grip on my QTextEdit - textEditTerminalRx?

      I realize English may not be your first language, but I really don't know what this means? Can you try to explain what it is you are trying to achieve such that we can help?

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

      @JonB
      Well... I want to set some text in me control (textEditTerminalRx). And I want to do it from some modules (cpp files)

      jsulmJ 1 Reply Last reply
      0
      • J jenya7

        @JonB
        Well... I want to set some text in me control (textEditTerminalRx). And I want to do it from some modules (cpp files)

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #7

        @jenya7 So, what stops you from doing:

        textEditTerminalRx->setText("MY TEXT");
        

        ?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        J 1 Reply Last reply
        2
        • Gojir4G Gojir4

          @jenya7
          Whe you design your form with the designer, an ui element is created in your widget's code.

          So calling ui->textEditTerminalRx should give you access to your text widget

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

          @Gojir4 said in How to use QTextEdit:

          @jenya7
          Whe you design your form with the designer, an ui element is created in your widget's code.

          So calling ui->textEditTerminalRx should give you access to your text widget

          It works in mainwindow.cpp. But ui->textEditTerminalRx is not visible in another files.

          jsulmJ Gojir4G 2 Replies Last reply
          0
          • jsulmJ jsulm

            @jenya7 So, what stops you from doing:

            textEditTerminalRx->setText("MY TEXT");
            

            ?

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

            @jsulm said in How to use QTextEdit:

            @jenya7 So, what stops you from doing:

            textEditTerminalRx->setText("MY TEXT");
            

            ?

            without ui-> is not visible.

            1 Reply Last reply
            0
            • J jenya7

              @Gojir4 said in How to use QTextEdit:

              @jenya7
              Whe you design your form with the designer, an ui element is created in your widget's code.

              So calling ui->textEditTerminalRx should give you access to your text widget

              It works in mainwindow.cpp. But ui->textEditTerminalRx is not visible in another files.

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #10

              @jenya7 said in How to use QTextEdit:

              But ui->textEditTerminalRx is not visible in another files

              And it should not.

              You don't provide enough information to help you.
              Did you use designer or not?

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • J jenya7

                @Gojir4 said in How to use QTextEdit:

                @jenya7
                Whe you design your form with the designer, an ui element is created in your widget's code.

                So calling ui->textEditTerminalRx should give you access to your text widget

                It works in mainwindow.cpp. But ui->textEditTerminalRx is not visible in another files.

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

                @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 JonBJ 2 Replies Last reply
                2
                • J jenya7

                  I placed QTextEdit on a form.
                  I see it in ui->setupUi(this);

                  textEditTerminalRx = new QTextEdit(tab_terminal);
                  textEditTerminalRx->setObjectName(QString::fromUtf8("textEditTerminalRx"));
                  textEditTerminalRx->setGeometry(QRect(80, 100, 521, 91));
                  

                  How can I set text in textEditTerminalRx? what visibility scope? it's not seen at mainwindow.cpp.

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

                  @jsulm said in How to use QTextEdit:

                  @jenya7 said in How to use QTextEdit:

                  But ui->textEditTerminalRx is not visible in another files

                  And it should not.

                  You don't provide enough information to help you.
                  Did you use designer or not?

                  Sorry but it is specified on the two first lines.

                  @jenya7 said in How to use QTextEdit:

                  I placed QTextEdit on a form.
                  I see it in ui->setupUi(this);

                  1 Reply Last reply
                  2
                  • 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