c++ - How to create a class inherited from QWidget with a class inherited from QMainWindow as parent -
here problem:
i want create class mainwindow (inherited qmainwindow qt class) , had other class in it, inherited qwidget qt class. seems don't work : http://pastebin.com/zjjw4ykq (error)
i can't pass "celestialbox::celestialbox(mainwindow *parent) : qwidget(parent)" parent qwidget because it's different type expected, worked class inherited qgroupbox don't understand ...
mainwindow.hpp
#ifndef mainwindow_hpp #define mainwindow_hpp #include <qapplication> #include <qpushbutton> #include <qmainwindow> #include <qtgui> #include "celestialbox.hpp" class mainwindow : public qmainwindow { q_object public: mainwindow(qwidget *parent = 0); ~mainwindow(); private: protected: public slots: }; #endif // mainwindow_hpp mainwindow.cpp
#include "mainwindow.hpp" mainwindow::mainwindow(qwidget *parent) : qmainwindow(parent) { } mainwindow::~mainwindow() { } celestialbox.cpp
#include "celestialbox.hpp" celestialbox::celestialbox(mainwindow *parent) : qwidget(parent) { setgeometry(5, 105, 295, 295); _parent = parent; _listobjects = new qlistwidget(this); _listobjects->setgeometry(10, 30, 275, 205); _add = new qpushbutton(this); _del = new qpushbutton(this); _add->setgeometry(10, 240, 135, 50); _del->setgeometry(150, 240, 135, 50); _add->settext("add / edit"); _del->settext("delete"); _del->setenabled(false); } celestialbox.hpp
#ifndef celestialbox_hpp #define celestialbox_hpp #include <qmainwindow> #include <qpushbutton> #include <qlistwidget> #include <qlistview> #include <qgroupbox> #include <qwidget> class mainwindow; class celestialbox : public qwidget { q_object public: celestialbox(mainwindow *parent = 0); ~celestialbox(); void cleanallfields(); void updatelistplanet(); private: qlistwidget *_listobjects; qpushbutton *_add; qpushbutton *_del; mainwindow *_parent; signals: public slots: }; #endif // celestialbox_hpp
my guess is: need include "mainwindow.hpp" in either "celestialbox.hpp" or celestialbox.cpp. santosh
c++ qt inheritance
No comments:
Post a Comment