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. Qt help
Forum Updated to NodeBB v4.3 + New Features

Qt help

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 3 Posters 691 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.
  • C Offline
    C Offline
    CharlesHuff
    wrote on last edited by
    #3

    I think SysManager is the class from sFoundation. myMgr is the instance of the class. What is "shadowed"? How may I use the class without it being shadowed assuming this is wrong?

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

      You did not answer my question: is myMgr a class member of MainWindow ?

      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
      • C Offline
        C Offline
        CharlesHuff
        wrote on last edited by
        #5

        Sorry, I don't think it could be...

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

          Do you realize that this is a yes/no type of question ?

          If not, you should really take the time to learn the C++ basics.

          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
          • C Offline
            C Offline
            CharlesHuff
            wrote on last edited by
            #7

            Thank you. I realize my questions are dumb.
            I did a tutorial on classes. I can write basic c++ code outside of Qt that runs ok. No other person/tutorial has used the "shadowed" term, but I did not mean to offend you by asking about it. I will google it. Syntax is a weakness for me. I use SysManager *myMgr; in the code. to me it means SysManager is the top level class. *myMgr is a pointer to an instance of that class. I do not know how to make the SysManager class merge with qt_object or with any Qt class, if that is even possible. The sFnd lib has other classes (IPort, INode, among others). I have code from online tutorials that show me how to write a class with private and public functions. When I try such code snippets, I get errors that say I am wrongly redefining class and/or class members. I really learn best with example code. I have yet to see any code from google search where an external shared library class is actually used in a Qt app in the way that I am trying to use this. Maybe my approach is all wrong. I did find another person who was struggling with this, but there was no resolution posted to his nearly identical questions. He asks:
            how is it possible that it works on VS and not in QT, arent the libraries independent from the Development environment? I will keep looking...

            jsulmJ 1 Reply Last reply
            0
            • C CharlesHuff

              Thank you. I realize my questions are dumb.
              I did a tutorial on classes. I can write basic c++ code outside of Qt that runs ok. No other person/tutorial has used the "shadowed" term, but I did not mean to offend you by asking about it. I will google it. Syntax is a weakness for me. I use SysManager *myMgr; in the code. to me it means SysManager is the top level class. *myMgr is a pointer to an instance of that class. I do not know how to make the SysManager class merge with qt_object or with any Qt class, if that is even possible. The sFnd lib has other classes (IPort, INode, among others). I have code from online tutorials that show me how to write a class with private and public functions. When I try such code snippets, I get errors that say I am wrongly redefining class and/or class members. I really learn best with example code. I have yet to see any code from google search where an external shared library class is actually used in a Qt app in the way that I am trying to use this. Maybe my approach is all wrong. I did find another person who was struggling with this, but there was no resolution posted to his nearly identical questions. He asks:
              how is it possible that it works on VS and not in QT, arent the libraries independent from the Development environment? I will keep looking...

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

              @CharlesHuff You put

              SysManager *myMgr;
              

              in constructor of your class. And you probably have added it also in your class declaration as member of your class, like:

              class MainWindow
              {
              private:
                  SysManager *myMgr;
              

              Do you see what the problem is?
              Your using another myMgr in your constructor which has no relation to the one declared in your class! This is what @SGaist means with "shadowing": myMgr in constructor hides ("shadows") myMgr declared as class member.

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

              1 Reply Last reply
              2
              • C Offline
                C Offline
                CharlesHuff
                wrote on last edited by
                #9

                I see class only used once in my whole Qt 6 project. Inside main window.h :
                class MainWindow : public QMainWindow statement is just before Q_OBJECT macro? followed by the
                MainWindow constructor and destructor...

                I didn't know to put SysManager *myMgr; there? and in fact I did not put it there....

                Confused is my middle name.

                jsulmJ 1 Reply Last reply
                0
                • C CharlesHuff

                  I see class only used once in my whole Qt 6 project. Inside main window.h :
                  class MainWindow : public QMainWindow statement is just before Q_OBJECT macro? followed by the
                  MainWindow constructor and destructor...

                  I didn't know to put SysManager *myMgr; there? and in fact I did not put it there....

                  Confused is my middle name.

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

                  @CharlesHuff I'm also confused by what you write to be honest.
                  Can you please post your MainWindow class declaration (from the header file)?

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

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

                    So we have the following situation:

                    • Variable scopes understanding issues (class members VS function local variables)
                    • Use of a singleton class

                    @CharlesHuff:

                    You did not offend me, you are new to C++ and this is a language that requires some work to be comfortable with hence my suggestion to get the basics correctly before diving further. There's a lot of code using Qt with external libraries. Qt itself uses external libraries. The whole KDE projects uses external libraries. The one you are currently using does not differ.
                    .
                    That said:

                    • you can't declare a variable in one function and use it in a different one (function local variables)
                    • I you need something reusable in a class, make it a class member
                    • You have a singleton object so it makes little sense to store a member variable for it
                    • When using a singleton, you grab it when needed in the functions that requires it,.
                      Why ? because the object may have been destroyed and recreated somewhere else in your code and thus your variable will point to some random memory.
                    • Don't try to use static variables for that, it's the wrong use case.

                    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
                    2
                    • C Offline
                      C Offline
                      CharlesHuff
                      wrote on last edited by
                      #12

                      @jsulm said in Qt help:

                      MainWindow

                      I can post it. It would be the exact same code that you get with a plain widget project. Your question lead me to move SysManager *myMgr; declaration there. like below:
                      '''
                      #ifndef MAINWINDOW_H
                      #define MAINWINDOW_H

                      include <QMainWindow"

                      #include <../../inc/inc-pub/pubSysCls.h>
                      QT_BEGIN_NAMESPACE
                      namespace ui { class MainWindow; }
                      {
                      Q_OBJECT
                      public: MainWindow(Widget *parent = nullptr);
                      ~MainWindow();

                      sFnd::SysManager *myMgr;
                      //above line is where you hinted me to put initialization of myMgr object so that one instance can be used
                      //in each on_button_clicked call...
                      //this seems to be working now. YAY! Thank you very much!

                      private slots:
                      void on_pushButtonInit_clicked();
                      private:
                      Ui::MainWindow *ui;
                      };
                      #endif // MAINWINDOW.H
                      '''

                      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