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. default argument error
Forum Update on Monday, May 27th 2025

default argument error

Scheduled Pinned Locked Moved General and Desktop
default argumenmainwindow
7 Posts 4 Posters 2.1k 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.
  • R Offline
    R Offline
    reina
    wrote on 6 Sept 2015, 19:16 last edited by
    #1

    why is qt forcing me to put a default argument here for img_path?
    AvailableTile(QWidget* parent = 0,QString img_path);

    my next question is,
    is it only okay to modify the ui_mainwindow myself? because i need it to modify

    O 1 Reply Last reply 6 Sept 2015, 19:28
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 6 Sept 2015, 19:22 last edited by
      #2

      hi
      what is AvailableTile ?
      Seems it has a constructor that wants two arguments instead of the normal parent only.

      ui_mainwindow is generated from the UI file by a program called moc.

      If you edit it, your modifications will be gone next time it is regenerated.

      Its far better to change stuff outside the file ,
      like in mainwindows constructor
      after
      ui->setupUi ( this );

      You can access any widget with ui->
      so anything you can do in ui_mainwindow you can do here and it is not overwritten.

      1 Reply Last reply
      0
      • R reina
        6 Sept 2015, 19:16

        why is qt forcing me to put a default argument here for img_path?
        AvailableTile(QWidget* parent = 0,QString img_path);

        my next question is,
        is it only okay to modify the ui_mainwindow myself? because i need it to modify

        O Offline
        O Offline
        Olivier Ronat
        wrote on 6 Sept 2015, 19:28 last edited by
        #3

        In fact you must put the default arguments from right to left. To solve your problem you must write :
        AvailableTile(QString img_path, QWidget* parent = 0);

        1 Reply Last reply
        0
        • R Offline
          R Offline
          reina
          wrote on 8 Sept 2015, 14:34 last edited by reina 9 Aug 2015, 14:42
          #4

          what is AvailableTile ?
          AvailableTile is a constuctor from AvailableTile class.

          AvailableTile(QWidget* parent = 0);
          this default constructor doesnt have any problem.
          **
          You can access any widget with ui->
          so anything you can do in ui_mainwindow you can do here and it is not overwritten**.
          grass = new AvailableTile(centralWidget); // this is the generated code of ui_mainwindow
          but i need it to be
          grass = new AvailableTile("../Desktop/grass.png",centralWidget);

          so how do i do that

          M 1 Reply Last reply 8 Sept 2015, 19:35
          0
          • R Offline
            R Offline
            reina
            wrote on 8 Sept 2015, 14:40 last edited by
            #5

            In fact you must put the default arguments from right to left. To solve your problem you must write :
            can you explain it to me why?

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 8 Sept 2015, 15:23 last edited by
              #6

              Hi,

              Because it's a rule of C++, see here

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • R reina
                8 Sept 2015, 14:34

                what is AvailableTile ?
                AvailableTile is a constuctor from AvailableTile class.

                AvailableTile(QWidget* parent = 0);
                this default constructor doesnt have any problem.
                **
                You can access any widget with ui->
                so anything you can do in ui_mainwindow you can do here and it is not overwritten**.
                grass = new AvailableTile(centralWidget); // this is the generated code of ui_mainwindow
                but i need it to be
                grass = new AvailableTile("../Desktop/grass.png",centralWidget);

                so how do i do that

                M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 8 Sept 2015, 19:35 last edited by
                #7

                @reina

                Perhaps AvailableTile has a function to set img_path after it has been constructed with the
                default constructor ?

                If not, you must create yourself and insert into the mainwindow.
                You cannot get Creator to use the other constructor via the UI generator.

                is AvailableTile your own class?

                1 Reply Last reply
                0

                3/7

                6 Sept 2015, 19:28

                • Login

                • Login or register to search.
                3 out of 7
                • First post
                  3/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved