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. Customizing QPushButton
Forum Updated to NodeBB v4.3 + New Features

Customizing QPushButton

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 2.8k 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.
  • J Offline
    J Offline
    jarred
    wrote on last edited by
    #1

    I'm attempting to make my own PushButton, but am having some issues with my constructor. I assume it's a very simple issue, but at the moment I can't think of what I'm doing wrong. My class is extremely simple at this point.

    @
    #ifndef PPUSHBUTTON_H
    #define PPUSHBUTTON_H

    #include <QPushButton>

    class PPushButton : public QPushButton
    {

    Q_OBJECT
    

    public:

    explicit PPushButton(QWidget* parent =  0) : QPushButton(parent) {}
    
    ~PPushButton();
    

    void released();

    };

    #endif // PPUSHBUTTON_H

    My errors are:

    /jrd/qtstresstest-build-desktop/mainwindow.o:: In function PPushButton': /jrd/qtstresstest-build-desktop/../qtstresstest/ppushbutton.h:11: error: undefined reference to vtable for PPushButton'
    /jrd/qtstresstest-build-desktop/../qtstresstest/ppushbutton.h:11: error: undefined reference to `vtable for PPushButton'
    :: error: collect2: ld returned 1 exit status
    @

    Any help would be much appreciated!

    EDIT: added @-tags for code formatting, Gerolf

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      You must implement the constructor in a .cpp file, not the header file. See "C++ FAQ 23.10":http://www.parashift.com/c++-faq-lite/strange-inheritance.html#faq-23.10 for an explanation.

      Also, you must implement the destructor and the method.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jarred
        wrote on last edited by
        #3

        I seem to be getting the same issues.
        in ppushbutton.h
        @
        #ifndef PPUSHBUTTON_H
        #define PPUSHBUTTON_H

        #include <QPushButton>

        class PPushButton : public QPushButton
        {
        Q_OBJECT
        public:
        explicit PPushButton(QWidget* parent = 0);
        virtual ~PPushButton();
        void released();
        };

        #endif // PPUSHBUTTON_H
        @

        in ppushbutton.cpp:

        @
        #include "ppushbutton.h"
        #include <iostream>
        using std::cout;
        using std::endl;
        PPushButton::PPushButton(QWidget *parent) : QPushButton(parent)
        {
        cout << "in ctor" << endl;
        }

        PPushButton::~PPushButton()
        {
        cout << "in dtor" << endl;
        }

        void PPushButton::released()
        {
        std::cout << "released" << std::endl;
        }
        @

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

          You seem or you do?
          Did you add your new .cpp file to the project and rebuild everything?

          @
          make clean
          qmake
          make
          @

          Or call rebuild in Qt Creator or your favorite IDE.

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • I Offline
            I Offline
            ivan.todorovich
            wrote on last edited by
            #5

            Delete the whole qtstresstest-build-desktop folder and recompile.

            o_o Sorry for my rusted english.

            1 Reply Last reply
            0

            • Login

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