D
D
Dimchik2021-03-07 17:49:33
Qt
Dimchik, 2021-03-07 17:49:33

Qt error: C2664 signals and slots. How to decide?

I am writing code and I get an error related to signals and slots. Error code: view.cpp:29: error: C2664: "QMetaObject::Connection QObject::connect(const QObject *,const char *,const QObject *,const char *,Qt::ConnectionType)": Ґў®§¬ ®¦® ЇаҐ®Ўа §®ў vm аЈг¬Ґв 2 Ё§ "void (__cdecl QTimer::* )(QTimer::QPrivateSignal)" ў "const char *" . An error is thrown by the view.cpp file. Help decide.

view.h:

#pragma once

#include <QGraphicsView>
#include <QGraphicsScene>
#include <QObject>

#include "player.h"
#include "virus.h"

class View :public QGraphicsView
{
public:
    View();
    void view_elements();

public slots:
    void addVirus();
    void deleteVirus();


private:
    QGraphicsScene mainScene;
    Player pl;
    Virus vir;
    View *v;
    QTimer     *timer; // Таймер
    QTimer *createVirus;


};


view.cpp

#include "view.h"
#include "player.h"

#include <QObject>
#include <QTimer>

View::View()
{

    setWindowTitle("Space Rangers");

    setRenderHint(QPainter::Antialiasing);

    setFrameStyle(0);
    setSceneRect(0, 0, 500,600);
    setFixedSize(500, 600);



    mainScene.setItemIndexMethod(QGraphicsScene::NoIndex);
    setScene(&mainScene);

    timer = new QTimer();
    connect(timer, &QTimer::timeout, &pl, &Player::moving);
    connect(timer, &QTimer::timeout, &vir, &Virus::moving);
    timer->start(1000 / 50);
    view_elements();

    connect(createVirus, &QTimer::timeout, v, View::addVirus());
    createVirus->start(40000);

}

void View::view_elements(){

    pl.setPos(205, 400);
    mainScene.addItem(&pl);
}

void View::addVirus(){
    
    Virus *virus = new Virus();
    mainScene.addItem(virus);  
    virus->setPos((qrand() % (251)) * ((qrand()%2 == 1)?1:-1),0);
}

Pay attention to the line:
connect(createVirus, &QTimer::timeout, v, View::addVirus());

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ighor July, 2021-03-07
@Dimpik

connect(createVirus, &QTimer::timeout, v, &View::addVirus);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question