I have this problem with the qt conect

-1

I miss error in the following code line:

 connect(timer, &QTimer::timeout, this, [this,x,y]() { lab.eliminarArtefactoPosible(x,y); });

The error that informs me is:

  

no matching function for call to 'MainWindow :: connect (QTimer * &, void (QTimer :: ) (QTimer :: QPrivateSignal), MainWindow , MainWindow :: drawArtifact () :: ) '

     

connect (timer, & QTimer :: timeout, this, this, x, and {lab.clearPossibleArt (x, y);});

Entire error function:

 void MainWindow::dibujarArtefacto() {

    int x = rand() % configuracion.tamanio;
    int y = rand() % configuracion.tamanio;
    lab.generarArtefacto(x,y);
    redibujar();
    QTimer *timer = new QTimer(this);
    connect(timer, &QTimer::timeout, this, [this,x,y]() { lab.eliminarArtefactoPosible(x,y); });

Class I want to connect:

void Laberinto::eliminarArtefactoPosible(int x, int y) {

    if (!mapa[x][y]->es_solido()) {
        delete mapa[x][y];
        mapa[x][y] = new Piso();
    }
  }

Here MainWindow.h:

namespace Ui {

    class MainWindow;
    }

class MainWindow : public QMainWindow {

    Q_OBJECT
    Ui::MainWindow *ui;

    public:
      explicit MainWindow(QWidget *parent = 0);
      ~MainWindow();
      void redibujar();
    private:
      QLabel *** labels;
      QLabel *status;
      Laberinto lab;

      QAction *guardarAct;
      QAction *cargarAct;
      QMenu *archivoMenu;

    void crearMenus();

    private slots:
      void dibujarArtefacto();
      void cargarPartida();
      void guardarPartida();
    
asked by JUAN 21.02.2018 в 20:51
source

1 answer

0
connect(timer, &QTimer::timeout, this, [this,x,y]() { lab.eliminarArtefactoPosible(x,y); });

The overload syntax for connect that you are using is as follows:

connect(SENDER, SIGNAL, RECEIVER, SLOT)

In this case, the problem is that the lambda does not belong to this (it is not a member function).

If you want to use a lambda you have the third argument left over:

connect(timer, &QTimer::timeout, [this,x,y]() { lab.eliminarArtefactoPosible(x,y); });
    
answered by 22.02.2018 в 07:46