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

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 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
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on 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

        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 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 last edited by reina
          #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

          mrjjM 1 Reply Last reply
          0
          • R Offline
            R Offline
            reina
            wrote on 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
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on 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

                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

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on 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

                • Login

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