
Originally Posted by
fitzy
guiClass
::guiClass (QWidget *parent
){
ui->setupUi(this);
//this->ui->progressBar->setValue(80); // IT WORKS, but it is in guiClass
anotherClass *anotherclass = new anotherClass(this);
anotherclass->anything();
}
guiClass ::guiClass (QWidget *parent)
: QMainWindow(parent), ui(new Ui::guiClass )
{
ui->setupUi(this);
//this->ui->progressBar->setValue(80); // IT WORKS, but it is in guiClass
anotherClass *anotherclass = new anotherClass(this);
anotherclass->anything();
}
To copy to clipboard, switch view to plain text mode
I knew it! you haven't set the pointer guiClass in anotherClass. So you accessing a null pointer!
Q_OBJECT
public:
void anything();
guiClass *guiClass;
void setBackPointer(guiClass *p) {guiClass = p;} // <- add
};
// and then
guiClass
::guiClass (QWidget *parent
){
ui->setupUi(this);
anotherClass *anotherclass = new anotherClass(this);
anotherclass->setBackPointer(this); // <- add
anotherclass->anything();
}
class anotherClass : public QProgressBar {
Q_OBJECT
public:
anotherClass(QObject* parent);
void anything();
guiClass *guiClass;
void setBackPointer(guiClass *p) {guiClass = p;} // <- add
};
// and then
guiClass ::guiClass (QWidget *parent)
: QMainWindow(parent), ui(new Ui::guiClass )
{
ui->setupUi(this);
anotherClass *anotherclass = new anotherClass(this);
anotherclass->setBackPointer(this); // <- add
anotherclass->anything();
}
To copy to clipboard, switch view to plain text mode
you can also use the parent of your constructor for setting the back pointer, but you really should learn signal and sots...
Bookmarks