c++ - Modify QStatusBar in QMainWindow without deleting it -


i'm confronted big problem actually, had qtabwidget contains multiple qwidget-herited object named tab , change qstatusbar in function of qtabwidget index qmainwindow delete qstatusbar (which in tab object) each time change tabs , causes application crash. here code

mainwindow.h

#ifndef tab_h #define tab_h  #include <qtwidgets>  class tab : public qwidget { public:     tab(int id);     qstatusbar *sbar;   private: };  #endif // tab_h 

mainwindow.cpp

#include "mainwindow.h" #include "tab.h" mainwindow::mainwindow() { tabs = new qtabwidget();  resize(800, 600);  connect(tabs, signal(currentchanged(int)), this, slot(currentchanged(int)));  for(int = 0; < 20; i++) {     tabs->addtab(new tab(i), qstring("%1").arg(i)); }  setcentralwidget(tabs); }  mainwindow::~mainwindow() {  }  void mainwindow::currentchanged(int) {     tab *thistab = static_cast<tab*>(sender());     setstatusbar(new qstatusbar()); } 

tab.h

#ifndef tab_h #define tab_h  #include <qtwidgets>  class tab : public qwidget { public:     tab(int id);     qstatusbar *sbar;   private:  };  #endif // tab_h 

tab.cpp

#include "tab.h"  tab::tab(int id) {     sbar = new qstatusbar();     qhboxlayout hbl;     qlabel *ll = new qlabel("statusbar tester: tab number : #"+qstring("%1").arg(id));     sbar->addwidget(new qlabel(qstring("%1").arg(id)));     hbl.addwidget(ll);     setlayout(&hbl);  } 

thanks patience


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -