Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    default argument error

    General and Desktop
    default argumen mainwindow
    4
    7
    1742
    Loading More Posts
    • 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
      reina last edited by

      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 Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by

        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 Reply Quote 0
        • O
          Olivier Ronat @reina last edited by

          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 Reply Quote 0
          • R
            reina last edited by 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

            mrjj 1 Reply Last reply Reply Quote 0
            • R
              reina last edited by

              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 Reply Quote 0
              • SGaist
                SGaist Lifetime Qt Champion last edited by

                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 Reply Quote 0
                • mrjj
                  mrjj Lifetime Qt Champion @reina last edited by

                  @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 Reply Quote 0
                  • First post
                    Last post