Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Help me understand C++ constructor syntax
Forum Updated to NodeBB v4.3 + New Features

Help me understand C++ constructor syntax

Scheduled Pinned Locked Moved Solved C++ Gurus
6 Posts 3 Posters 978 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.
  • A Offline
    A Offline
    Anonymous_Banned275
    wrote on last edited by Anonymous_Banned275
    #1

    APPEND

    I am not sure if this is a good idea - adding to older post , so I may copy it into a new post .

    I am again at lost analyzing this syntax.

    I have some udersting of the "new" entried, but I do not get this part

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),

    Would it be possible to get an expiation in English ?

    I am trying to convert QMainWindow class to QWidget.

    //! [0]
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        m_ui(new Ui::MainWindow),
        m_status(new QLabel),
        m_console(new Console),
        m_settings(new SettingsDialog),
    //! [1]
        m_serial(new QSerialPort(this))
    //! [1]
    

    DeviceDiscoveryDialog::DeviceDiscoveryDialog(QWidget *parent)
    : QDialog(parent), localDevice(new QBluetoothLocalDevice),
    ui(new Ui_DeviceDiscovery)
    {

    Where would be a good resource to learn this?

    I actually need to get info on "localDevice" , and have never used C++ this way.

    Actually this complex constructor is used by passing null pointer , or better - passing default NULL pointer
    as QWidget *parent). Little too complex for me...

    If it is OK - I could probably get started if somebody reads me the code in English...

    Thanks

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #2
      // Create an instance of DeviceDiscoveryDialog
      // and pass a "parent" parameter of type QWidget* to the constructor
      DeviceDiscoveryDialog::DeviceDiscoveryDialog(QWidget *parent)
      
      // Call the constructor of base class QDialog and pass the "parent" parameter to it
      : QDialog(parent),
      
      // dynamically allocate an instance of class QBluetoothLocalDevice
      // initialize member DeviceDiscoveryDialog::localDevice using that instance
      localDevice(new QBluetoothLocalDevice),
      
      // dynamically create an instance of class Ui_DeviceDiscovery
      // initialize member DeviceDiscoveryDialog::ui  using that instance
      ui(new Ui_DeviceDiscovery)
      

      Where would be a good resource to learn this?

      Probably any C++ book e.g. "A Tour of C++".
      If you prefer online resource cppreference page about constructors is a good place to start.

      1 Reply Last reply
      1
      • D Offline
        D Offline
        DerReisende
        wrote on last edited by
        #3

        I would like to throw this page into the ring which explains member initializer lists from the beginning.

        A 1 Reply Last reply
        0
        • A Offline
          A Offline
          Anonymous_Banned275
          wrote on last edited by
          #4

          Thank you very much for replies. Appreciate the help.

          I think I asked this before - would "allocate an instance of class" be same as " build an object of class " ?

          Chris KawaC 1 Reply Last reply
          0
          • D DerReisende

            I would like to throw this page into the ring which explains member initializer lists from the beginning.

            A Offline
            A Offline
            Anonymous_Banned275
            wrote on last edited by
            #5

            @DerReisende This is also "correct answer
            . Thanks.

            1 Reply Last reply
            0
            • A Anonymous_Banned275

              Thank you very much for replies. Appreciate the help.

              I think I asked this before - would "allocate an instance of class" be same as " build an object of class " ?

              Chris KawaC Offline
              Chris KawaC Offline
              Chris Kawa
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @AnneRanch said:

              would "allocate an instance of class" be same as " build an object of class "

              Yes

              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