In my MainWindow class, I'm creating a class and passing QLabels like so:
new_class = new NewClass(QLabel1, QLabel2);
new_class = new NewClass(QLabel1, QLabel2);
To copy to clipboard, switch view to plain text mode
NewClass constructor:
NewClass
::NewClass(QLabel *qLabel1,
QLabel *qLabel2
) : qLabel1
(qLabel1
), qLabel2
(qLabel2
){
}
NewClass::NewClass(QLabel *qLabel1, QLabel *qLabel2) : qLabel1(qLabel1), qLabel2(qLabel2)
{
}
To copy to clipboard, switch view to plain text mode
NewClass definition
{
Q_OBJECT
public:
private:
}
class NewClass : public QObject
{
Q_OBJECT
public:
NewClass(QLabel *qLabel1, QLabel *qLabel2);
private:
QLabel *qLabel1;
QLabel *qLabel2;
}
To copy to clipboard, switch view to plain text mode
The above method works fine and I am able to access and directly modify the QLabels in the main window from new_class. However, I am wondering if there is a better way to do this?
I believe this method will get quite tedious when I may need to access and modify many more objects contained in the MainWindow (as I will have to pass every single widget!).
Can I just pass a reference to the entire MainWindow?
Any help or insight would be kindly appreciated
Bookmarks