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. Instantiate a constructor with QObject *objectParent as the default parameter?
Forum Updated to NodeBB v4.3 + New Features

Instantiate a constructor with QObject *objectParent as the default parameter?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 295 Views
  • 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.
  • C Offline
    C Offline
    Calicoder
    wrote on last edited by
    #1

    Howdy fellow QT'ers, wondering how I'd go about making an instance of a class that has a constructor like this? I've tried all sorts of solutions including

    TestClass testClass(qobject_cast<QObject* objectClass>);
    

    and still no luck. Thanks

    The constructor looks like this:

    TestClass(QObject * objectParent)
    
    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Calicoder said in Instantiate a constructor with QObject *objectParent as the default parameter?:

      TestClass testClass(qobject_cast<QObject* objectClass>)

      this does not even compile...

      your class you pass has to derive from QObject.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • C Offline
        C Offline
        Calicoder
        wrote on last edited by
        #3

        The TestClass does belong to QObject already

        class TestClass : public QObject
        {
             Q_OBJECT
             public:
                  TestClass(QObject * objectParent);
        
        1 Reply Last reply
        0
        • C Offline
          C Offline
          Calicoder
          wrote on last edited by
          #4

          There we go, got it to work now by adding = nullptr to the TestClass constructor like this:

          TestClass(QObject * objectParent = nullptr)
          

          Thanks so much.

          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