Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Inheritance Class Subclass Problem (simple)
Forum Updated to NodeBB v4.3 + New Features

Inheritance Class Subclass Problem (simple)

Scheduled Pinned Locked Moved General and Desktop
10 Posts 5 Posters 2.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MrNoway
    wrote on 1 Feb 2013, 07:41 last edited by
    #1

    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 dispalyed

    What 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.

    1 Reply Last reply
    0
    • K Offline
      K Offline
      KA51O
      wrote on 1 Feb 2013, 07:48 last edited by
      #2

      Where do you call the constructor of your Point class and add the label to you mainwindow? To answer your question we need to see more code. All I can deduce is that the label from your Point class has widget_map_bg as its parent.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        MrNoway
        wrote on 1 Feb 2013, 08:19 last edited by
        #3

        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();
        }@

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lgeyer
          wrote on 1 Feb 2013, 08:26 last edited by
          #4

          Both widgets, <code>widget_map_bg</code> and <code>label</code>, have not been added to a layout.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            MrNoway
            wrote on 1 Feb 2013, 08:34 last edited by
            #5

            could you explain it a little bit more?

            which layout?

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on 1 Feb 2013, 10:07 last edited by
              #6

              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.

              1 Reply Last reply
              0
              • M Offline
                M Offline
                MrNoway
                wrote on 1 Feb 2013, 10:11 last edited by
                #7

                I just used a simple example to make it clearly what I want.

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andre
                  wrote on 1 Feb 2013, 10:13 last edited by
                  #8

                  [quote author="MrNoway" date="1359713487"]I just used a simple example to make it clearly what I want.
                  [/quote]
                  If you did, then you failed. It only managed to confuse me, obviously.

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    MrNoway
                    wrote on 1 Feb 2013, 10:26 last edited by
                    #9

                    Which part?

                    I simply want to make a QLabel parent over a QWidget from another class.

                    This cant be so difficult.

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      DerManu
                      wrote on 1 Feb 2013, 11:39 last edited by
                      #10

                      [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.

                      1 Reply Last reply
                      0

                      1/10

                      1 Feb 2013, 07:41

                      • Login

                      • Login or register to search.
                      1 out of 10
                      • First post
                        1/10
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved