c++ - How to access ui components from another class? -


i trying call method called display_txt() my_class. method supposed change text in label. method doesn't make changes ui. know method runs due qdebug(). no errors occur, label doesn't change "text changed". display_txt() works fine , changes label when called main widget class. there similar question in forums couldn't use solutions. make object when button btn pressed.

here code:

widget.h

#include <qwidget> namespace ui { class widget; }  class widget : public qwidget { q_object public: explicit widget(qwidget *parent = 0); ~widget(); void display_txt();  private slots: void on_btn_clicked();  private: ui::widget *ui; }; 

my_class.h

#include <qwidget> #include "widget.h"  class my_class : public qwidget { q_object public: explicit my_class(qwidget *parent = 0); void test(ui::widget ui1); signals: private: widget *wo = new widget; }; 

widget.cpp

#include "widget.h" #include "ui_widget.h" #include <qdebug> #include "my_class.h"  widget::widget(qwidget *parent) : qwidget(parent), ui(new ui::widget) { ui->setupui(this);  //display_txt(); qdebug() << "widget object created";  } void widget::display_txt(){ ui->lbl->settext("text changes!!!!!"); qdebug() << "display_txt() method finished";  } void widget::on_btn_clicked() { my_class mc; } 

my_class.cpp

#include "my_class.h" #include "qdebug"  my_class::my_class(qwidget *parent) : qwidget(parent) { qdebug() << "myclass ran"; wo->display_txt(); } 


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -