Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Customizing QPushButton
Qt 6.12 LTS is out! See what's new in the release blog

Customizing QPushButton

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 3.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.
  • ? Offline
    ? Offline
    A Former User
    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
    • ? Offline
      ? Offline
      A Former User
      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.

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        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
        • ? Offline
          ? Offline
          A Former User
          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.

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

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

            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
            • Unsolved