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. [SOLVED] textEdit not letting me access any of its functions
Qt 6.11 is out! See what's new in the release blog

[SOLVED] textEdit not letting me access any of its functions

Scheduled Pinned Locked Moved General and Desktop
19 Posts 4 Posters 6.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.
  • raven-worxR Offline
    raven-worxR Offline
    raven-worx
    Moderators
    wrote on last edited by
    #2

    first of all use code tags.

    the error message tells you that the compiler doesn't know the type of "programTextEdit". Did you include your ui-header file?

    --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
    If you have a question please use the forum so others can benefit from the solution in the future

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

      Hi and welcome to devnet,

      Please encode your code in coding tags that will make it readable.

      Your are missing
      @#include <QTextEdit>@

      in your cpp file so the compiler doesn't know what it is

      edit: getting closer :D
      edit2: I missread the error, you are missing your ui_xxx include. The compiler doesn't know what ui is.

      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
      • R Offline
        R Offline
        rizoritis
        wrote on last edited by
        #4

        Hey, thanks for the quick responses and sorry about the code tags.

        I did include ui_basicgui.h in my project. It wasn't <QTextEdit> either. Here is the code again:

        @#include "basicgui.h"
        #include "ui_basicgui.h"
        #include "loadfile.h"
        #include "ui_loadfile.h"
        #include "ui_selectfile.h"
        #include "selectfile.h"
        #include <QtDebug>

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

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

        void BasicGui::on_loadProgramButton_clicked()
        {
        LoadFile loadFileDialog;
        loadFileDialog.setModal(true);
        loadFileDialog.exec();
        }

        void BasicGui::on_selectProgramButton_clicked()
        {
        SelectFile selectFileDialog;
        selectFileDialog.setModal(true);
        selectFileDialog.exec();
        }

        void BasicGui::displayProgram(QString aPath)
        {
        QFile programFile(aPath);
        programFile.open(QIODevice::ReadOnly);
        QTextStream textStream(&programFile);
        QString line = textStream.readAll();
        programFile.close();

        qDebug() << line;
        ui->programTextEdit->setPlainText(line);
        ui->runButton->setEnabled(true);
        ui->pauseButton->setEnabled(true);
        

        }
        @

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #5

          and you are sure Ui::BasicGui has a QTextEdit named "programTextEdit"?
          If so, try to clean your project, run qmake again and build the project again.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • R Offline
            R Offline
            rizoritis
            wrote on last edited by
            #6

            I checked the ui_basicgui.h header and found it there:

            @class Ui_BasicGui
            {
            public:
            QWidget *centralWidget;
            QGroupBox *groupBox;
            QGridLayout *gridLayout;
            QHBoxLayout *horizontalLayout;
            QRadioButton *radioButton;
            QRadioButton *radioButton_2;
            QRadioButton *radioButton_3;
            QPushButton *machineOnButton;
            QPushButton *machineOffButton;
            QGroupBox *groupBox_4;
            QGridLayout *gridLayout_5;
            QGroupBox *groupBox_2;
            QFormLayout *formLayout;
            QLineEdit *lineEdit;
            QGridLayout *gridLayout_2;
            QPushButton *zPlusButton;
            QPushButton *yPlusButton;
            QPushButton *xMinusButton;
            QPushButton *xPlusButton;
            QPushButton *yMinusButton;
            QPushButton *zMinusButton;
            QGroupBox *groupBox_8;
            QGridLayout *gridLayout_3;
            QRadioButton *radioButton_4;
            QRadioButton *radioButton_5;
            QGroupBox *groupBox_6;
            QGridLayout *gridLayout_7;
            QTextEdit *programTextEdit;
            QPushButton *selectProgramButton;
            QGroupBox *groupBox_7;
            QGridLayout *gridLayout_8;
            QSlider *horizontalSlider;
            QPushButton *eStopButton;
            QWidget *layoutWidget;
            QVBoxLayout *verticalLayout_4;
            QGroupBox *groupBox_3;
            QGridLayout *gridLayout_10;
            QGridLayout *gridLayout_4;
            QLabel *label_4;
            QLabel *xPosActualLabel;
            QLabel *label_5;
            QLabel *yPosActualLabel;
            QLabel *label_6;
            QLabel *zPosActualLabel;
            QGroupBox *groupBox_5;
            QGridLayout *gridLayout_11;
            QGridLayout *gridLayout_6;
            QLabel *label_7;
            QLabel *xVelActualLabel;
            QLabel *label_8;
            QLabel *yVelActualLabel;
            QLabel *label_9;
            QLabel *zVelActualLabel;
            QWidget *layoutWidget1;
            QHBoxLayout *horizontalLayout_3;
            QPushButton *runButton;
            QPushButton *pauseButton;
            QPushButton *loadProgramButton;
            QToolBar *mainToolBar;
            QStatusBar *statusBar;@

            1 Reply Last reply
            0
            • I Offline
              I Offline
              itsmemax
              wrote on last edited by
              #7

              [quote author="raven-worx" date="1368705257"]If so, try to clean your project, run qmake again and build the project again.[/quote]

              Did you do this already? If not, try it please.

              1 Reply Last reply
              0
              • R Offline
                R Offline
                rizoritis
                wrote on last edited by
                #8

                Yes, I did clean the project and run qmake. Sorry, I forgot to mention that in my last post.

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  rizoritis
                  wrote on last edited by
                  #9

                  Just to clarify, nothing in my textEdit ("programTextEdit") works. I get the same error when I try accessing anything in the ui.

                  1 Reply Last reply
                  0
                  • R Offline
                    R Offline
                    rizoritis
                    wrote on last edited by
                    #10

                    I played around. If I put the following lines:

                    @ ui->programTextEdit->setPlainText(line);
                    ui->runButton->setEnabled(true);
                    ui->pauseButton->setEnabled(true);@

                    in the constructor, I get no build error. The errors only come up if I throw it in a separate function within my source file. Why is that?

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

                      Is your separate function a member of BasicGui ?

                      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
                      • R Offline
                        R Offline
                        rizoritis
                        wrote on last edited by
                        #12

                        Yup. See below (displayProgram):

                        @#ifndef BASICGUI_H
                        #define BASICGUI_H

                        #include <QMainWindow>
                        #include <QtGui>
                        #include <QtCore>

                        namespace Ui {
                        class BasicGui;
                        }

                        class BasicGui : public QMainWindow
                        {
                        Q_OBJECT

                        public:
                        explicit BasicGui(QWidget *parent = 0);
                        ~BasicGui();
                        static void displayProgram(QString);

                        private slots:
                        void on_selectProgramButton_clicked();
                        void on_loadProgramButton_clicked();

                        private:
                        Ui::BasicGui *ui;

                        };

                        #endif // BASICGUI_H@

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

                          So you are trying to modify a private class member from a static function ?

                          That's not allowed

                          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
                          • R Offline
                            R Offline
                            rizoritis
                            wrote on last edited by
                            #14

                            [quote author="SGaist" date="1368717950"]So you are trying to modify a private class member from a static function ?

                            That's not allowed[/quote]

                            OK, I made the function non-static, but am now getting a function saying "error: C2352: 'BasicGui::displayProgram' : illegal call of non-static member function" when trying to call the function from another class/file with the following code:

                            @ BasicGui::displayProgram(aPath);@

                            1 Reply Last reply
                            0
                            • raven-worxR Offline
                              raven-worxR Offline
                              raven-worx
                              Moderators
                              wrote on last edited by
                              #15

                              @
                              ui->displayProgram(aPath);
                              @

                              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                              If you have a question please use the forum so others can benefit from the solution in the future

                              1 Reply Last reply
                              0
                              • R Offline
                                R Offline
                                rizoritis
                                wrote on last edited by
                                #16

                                [quote author="raven-worx" date="1368719638"]@
                                ui->displayProgram(aPath);
                                @[/quote]

                                displayProgram() is from another class (Ui::BasicGui) so when I do that it says that displayProgram is not a member of the class that I am making the call in (which in this case is called Ui::SelectFile).

                                1 Reply Last reply
                                0
                                • R Offline
                                  R Offline
                                  rizoritis
                                  wrote on last edited by
                                  #17

                                  I got it to work. I didn't make an object of BasicGui in my SelectFile class. I did the following for it to work:

                                  @public:
                                  explicit SelectFile(QWidget *parent = 0);
                                  ~SelectFile();
                                  BasicGui *basicgui;
                                  @

                                  Then I made a call to basicgui->displayProgram()

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

                                    Your code looks like it's getting messy. You are starting to have pointers to objects not directly related to those you are using.

                                    May I suggest reading some of the examples from the Qt documentation ?

                                    Typically updating your line edit content from another widget should be done using signals and slots (Unless I misunderstood your code). Or if SelectFile is a dialog to select a file (like the name suggests) why not use QFileDialog from BasicGui and directly update the line edit ?

                                    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
                                    • R Offline
                                      R Offline
                                      rizoritis
                                      wrote on last edited by
                                      #19

                                      OK. I will do some HW. Thanks!

                                      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