Inheritance Class Subclass Problem (simple)
-
Hi everyone.
I have little problem that kills me.I have one main class and a subclass that is derived fromt he main class
main class Lines
subclass Point@class Lines : public QMainWindow{
Q_OBJECT
public:
QWidget *widget_map_bg;
Lines();################################################
Lines::Lines(QWidget *parent) : QMainWindow ( parent ){
ui.setupUi(this);
widget_map_bg = new QWidget(ui.centralwidget);
}@AND
@
class Point : Lines(){
Q_OBJECT
public:
Point();
QLabel *label;
};################################################
Point::Point(){
label = new QLabel(widget_map_bg);
label->setText("HALLO");}
@
My Problem is, the text does not show up.
I tried also using pixmap and other things but nothing wants to be dispalyedWhat did I do wrong?
thanks
if I exchange the code with this
@ label = new QLabel();
label->show@then a seperate widget is created and displayed,
so the code is actually working. -
hi, thanks for your answer,
I just tried to reduce as much as possible making it easier to overview.
okay here is the main
main.cpp
@
int main( int argc, char *argv[] )
{
QApplication app( argc, argv);
Lines w;
w.resize(1280,720);
w.move(100, 100);Point p;
w.show();return app.exec();
}@ -
I think you totally misunderstand subclassing, MrNoway.
Why do you think Lines should inherit QMainWindow, and points should inherit Lines? Do you really mean to express that a Point is a Lines, which is a QMainWindow? That shound just weird to me.I'd think that all you want to do is have your QMainWindow render some lines and some points. But that does not require anything like you're trying to do here.
Please get yourself a decent C++ book to get familiar with the basics a bit. Without understanding the basics of C++, you're not going to be able to work effectively with Qt either.
-
[quote author="MrNoway" date="1359714403"]I simply want to make a QLabel parent over a QWidget from another class. This cant be so difficult.[/quote]
Probably the other way around, right? i.e. something like label.setParent(widget).You're right. It's not so difficult. But you just lack C++/Qt basics, so it would benefit you much more to learn them in a systematic manner (e.g. a book or an extensive read in the Qt documentation) than asking specific questions in fora. Anyhow, as André has said, subclassing is the wrong tool for parenting. Have a look at the QObject parenting system.