Planned maintenance has been done but it did not solve the problem. So work will continue on this and a new time for trying updates will be announced asap.

default argument error



  • 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


  • Lifetime Qt Champion

    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.



  • 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);



  • 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



  • 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?


  • Lifetime Qt Champion

    Hi,

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


  • Lifetime Qt Champion

    @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?