Qt help
-
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?
-
You did not answer my question: is myMgr a class member of MainWindow ?
-
Sorry, I don't think it could be...
-
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.
-
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... -
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...@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. -
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.
-
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.
@CharlesHuff I'm also confused by what you write to be honest.
Can you please post your MainWindow class declaration (from the header file)? -
So we have the following situation:
- Variable scopes understanding issues (class members VS function local variables)
- Use of a singleton class
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.
-
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_Hinclude <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
'''