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] Problem with get method
Forum Updated to NodeBB v4.3 + New Features

[Solved] Problem with get method

Scheduled Pinned Locked Moved General and Desktop
10 Posts 2 Posters 2.0k 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.
  • S Offline
    S Offline
    silep
    wrote on last edited by
    #1

    Hello,

    I have a problem with the use of the get method, I think the synthax of something is wrong but I don't know where.. Would anyone see what is wrong?

    I write here the important lines

    ui_mainform.h:

    @class Ui_MainForm
    {
    public:
    QTextEdit *errorBrowser;

    void setupUi(QMainWindow *MainForm)
    {
    errorBrowser = new QTextEdit(centralwidget);
    errorBrowser->setObjectName(QStringLiteral("errorBrowser"));
    errorBrowser->setGeometry(QRect(500, 490, 491, 121));
    errorBrowser->setReadOnly(true);
    }
    };@

    mainform.h:

    @class MainForm : public QMainWindow,
    private Ui::MainForm // Die Klasse MainForm wird in der automatisch erzeugten Header-Datei ui_mainform.h automatisch erstellt
    {
    Q_OBJECT

    public:
    explicit MainForm(QWidget parent = 0);
    MainForm::~MainForm();
    QTextEdit
    getBrowser() const;

        private:
    

    Ui::MainForm *ui;
    };@

    mainform.cpp:

    @MainForm::MainForm(QWidget *parent)
    : QMainWindow(parent)
    {
    ui->setupUi(this);

    camXPos = "ERROR!";
    camXPos = "ERROR!";
    camZPos = "ERROR!";

    }

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

    QTextEdit* MainForm::getBrowser() const
    {
    return ui->errorBrowser;
    }@

    errorMsg.h:

    @class errorMsg : public QObject
    {
    Q_OBJECT

    public:
    errorMsg();
    ~errorMsg();

    QTextEdit *browser;
    };@

    errorMsg.cpp:

    @errorMsg::errorMsg()
    {
    browser = MainForm::getBrowser();
    }

    errorMsg::~errorMsg()
    {}@

    The problem comes with the constructor of errorMsg, the error message says

    @errorMsg.cpp(8): error C2352: 'MainForm::getBrowser' : illegal call of non-static member function
    copy2\linsenmessplatz3\mainform.h(35) : see declaration of 'MainForm::getBrowser'@

    Thank you in advance for your advises!

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      You probably need to remove "const" from getBrowser().

      (Z(:^

      1 Reply Last reply
      0
      • S Offline
        S Offline
        silep
        wrote on last edited by
        #3

        Thank you for your reply.
        I just tried that but it doesn't change anything.

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          Ah, sorry, I have missed that line:
          @
          browser = MainForm::getBrowser();
          @

          This is obviously wrong. You need to either make MainWindow into a Singleton, or change the architecture of your project (I advise the latter).

          (Z(:^

          1 Reply Last reply
          0
          • S Offline
            S Offline
            silep
            wrote on last edited by
            #5

            Ok, and to change the architecture of my project I have to create a new QWidget project and insert my programm in? What is wrong with my current architecture?

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              You cannot invoke getBrowser() without an object (MainWindow instance). So, you need to restructure your code so that you can pass the pointer to that object into your errorMsg class.

              This is also not an ideal solution (why on Earth should error handling class be aware that a GUI exists?), but it will at least work.

              Yet another option would be to sent a signal from errorMsg to MainWindow, and handle the text changing there (that solution seems way better).

              (Z(:^

              1 Reply Last reply
              0
              • S Offline
                S Offline
                silep
                wrote on last edited by
                #7

                Would this signal have this form?

                @QTextEdit *line = new QTextEdit("Hello");
                connect(line, SIGNAL(signalChangeText(QString)), Ui_MainForm::errorBrowser, SLOT(changeText(QString)));@

                There is still the static variable problem with the errorBrowser.

                1 Reply Last reply
                0
                • sierdzioS Offline
                  sierdzioS Offline
                  sierdzio
                  Moderators
                  wrote on last edited by
                  #8

                  Correct.
                  @
                  connect(line, SIGNAL(signalChangeText(QString)), ui->errorBrowser, SLOT(changeText(QString)));
                  @

                  (Z(:^

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    silep
                    wrote on last edited by
                    #9

                    Ok, but my @ui is undefined@

                    It wasn't defined when I took the project, so that I had to define it manually than a new Widget project with Qt Creator, but something is probably wrong. I defined it in the Mainform.h that I shown at the beginning of the topic.

                    The Mainform produces a ui_MainForm file too, which defines the QWidgets and theirs proprieties. I don't know if I can create both *ui and ui_Mainform..

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      silep
                      wrote on last edited by
                      #10

                      I made some changes, and now it seems to be a little better, but there are some new errors. I had to define Ui::MainForm *ui; in both mainform.h and errorMsg.h to avoid the old errors with "undefined ui", even if I have no idea if it works well..

                      The errors are now:

                      @errorMsg.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall errorMsg::metaObject(void)const " (?metaObject@errorMsg@@UBEPBUQMetaObject@@XZ)

                      errorMsg.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall errorMsg::qt_metacast(char const *)" (?qt_metacast@errorMsg@@UAEPAXPBD@Z)

                      errorMsg.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall errorMsg::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@errorMsg@@UAEHW4Call@QMetaObject@@HPAPAX@

                      And my new MainForm.h

                      @#include <QMainWindow>

                      namespace Ui {
                      class MainForm;
                      }

                      class MainForm : public QMainWindow,
                      private Ui::MainForm // ui_mainform.h automatic creation
                      {
                      Q_OBJECT

                      public:
                      explicit MainForm(QWidget *parent = 0);
                      ~MainForm();

                          private:
                      

                      Ui::MainForm *ui;
                      };@

                      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