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. Create a simple constructor with parameters
Forum Updated to NodeBB v4.3 + New Features

Create a simple constructor with parameters

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 4.2k 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.
  • R Offline
    R Offline
    rivercreekocean
    wrote on last edited by
    #1

    I'm trying to make it so my widget will open a new window when a button is pressed, and there will be things in that window. I'm pretty sure I need a new class to do this, and I need variables from the main window in this new class, so I'm going to need a constructor with parameters. I have the constructor that comes with each class, that has only the QWidget parent as a parameter:

    explicit MyWindow(QWidget *parent = 0);

    but everytime I try to add a new variable to that list it gives me an error (missing default parameter for parameter 2) or a warning (unreferenced formal parameter). I'm also not certain how to pass pointers to when I create the new object, as I don't know what to pass for the parent parameter, would it just be "this"?

    Basically, need to make a new class, and pass it pointers to variables, so that I can make a window launched from another window. Can someone help me?

    EDIT: I think I actually figured out how to add the parameters, the same was as in C++, but the compiler was barking at me because I was still designing it and hadn't implemented any definition for the parameters (giving me the unreferenced formal parameter warning). Still not sure how to create a new object of it, though.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mmallad
      wrote on last edited by
      #2

      If your new class inherits QWidget than you can pass this as parameter otherwise you dont need to pass the parent parameter as it had default value 0.
      The reason behind passing this parameter is that when the parent gets deleted than child will also automatically deleted.

      Dpak Malla

      1 Reply Last reply
      0
      • R Offline
        R Offline
        rivercreekocean
        wrote on last edited by
        #3

        Alright thanks, I think that worked.

        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