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. [SOLVED] What's the stuff after the colon mean on this function definition?
Qt 6.11 is out! See what's new in the release blog

[SOLVED] What's the stuff after the colon mean on this function definition?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.1k Views 2 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
    maximo
    wrote on last edited by maximo
    #1

    Newbie here. In the snippet below, what's the stuff after the single colon mean? Coming from the PHP world, I understand what the :: means, but not the single colon in this context:

    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
    /snip
    

    The part I'm talking about begins with QMainWindow...

    1 Reply Last reply
    0
    • JohanSoloJ Offline
      JohanSoloJ Offline
      JohanSolo
      wrote on last edited by
      #2

      This is basic C++: the MainWindow::MainWindow(QWidget *parent) is the declaration of the MainWindow constructor as you've probably guessed, and MainWindow class inherits from QMainWindow. The part between the colon and the opening brace is the member initialiser list: it actually calls the constructor of the mother class and of the members.
      Whilst the members can be initialised in the constructor body, the mother class cannot, therefore it is the mandatory part of this `stuff'. The mother class constructor must be the first called constructor in that section. Then using this mechanism to initialise class members or do it in the constructor itself is kind of up to you.

      `They did not know it was impossible, so they did it.'
      -- Mark Twain

      1 Reply Last reply
      3
      • M Offline
        M Offline
        maximo
        wrote on last edited by
        #3

        Since it's a comma-delimited list, can I assume that it inherits from both QMainWindow and the ui class too?

        E 1 Reply Last reply
        0
        • M maximo

          Since it's a comma-delimited list, can I assume that it inherits from both QMainWindow and the ui class too?

          E Offline
          E Offline
          Esperantisto
          wrote on last edited by
          #4

          @maximo said:

          Since it's a comma-delimited list, can I assume that it inherits from both QMainWindow and the ui class too?

          ui is probably a member.

          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