Hello.
I have two classes
//Ah #ifndef A_H #define A_H #include <QtGui> #include <QDebug> #include "ui_A.h" #include "Bh" #include <QLine> #include <QCoreApplication> class A : public QDialog, public Ui::DialogClass { Q_OBJECT public: A(QWidget* parent = 0); ~A(); bool getValue() { return _value; } public slots: private slots: private: B* b; bool _value; protected: void paintEvent(QPaintEvent *); }; #endif // A_H //Bh #ifndef B_H #define B_H #include <QtGui> #include "ui_B.h" //class Dialog; class B : public QWidget, public Ui::MyWidgetClass//,public QObject { Q_OBJECT public: B(QWidget *parent = 0); ~B(); //B(QObject *parent = 0); protected: signals: public slots: private: A* my1; }; #endif // B_H //B.cpp #include <QDebug> #include "Ah" B::B(QWidget *parent) : QWidget(parent) { setupUi(this); } B::~B() { } void B::on_button1_clicked() { //if(my1->getVaue() == true)//Как тут использовать getvalue()?? //my1->getValue() = false; // else // my1->getValue() = true; update(); // qDebug()<<"text"; } //main.cpp #include "Ah" #include <QtGui> #include <QApplication> #include "Bh" int main(int argc, char *argv[]) { QApplication app(argc, argv); A a; //B my1; a.show(); return app.exec(); }
Question. How to use the _value field from class A in class B?
B
wants to have access to instanceA
, then accordingly in classB
should be a pointer toA
- VladDbh
remove the#include "Ah"
and just addclass A;
. And inb.cpp
just the opposite add#include "Ah"
. - VladDmy1
equals something incomprehensible, and you already dereference it. You first initialize the variablemy1
, andmy1->_isBeingMouse1=false;
- this is a reference to a variable. - VladD