Chris
Chris

Reputation: 85

Slot doesnt exist in connect function in C++/Qt project? (already reran make)

I am adding a slider bar to easyPaint, which will enable a zoom function. I have the slider appearing where I want it on the screen, and the function I built for it shouldn't have any issues, but when I run it, I get a runtime error that the slot doesn't exist, when it clearly does. I have already tried cleaning the solution, rerunning CMake, and rebuilding, and still get the "slot does not exist" error every time. Can anyone else think of any other reason why I would get this issue?

Here is the setup of the dock with slider, within the mainwindow class:

dock = new QDockWidget(tr("Zoom"));
slider = new QSlider(dock);
addDockWidget(Qt::BottomDockWidgetArea, dock);
dock->setWidget(slider);
dock->setFeatures(QDockWidget::NoDockWidgetFeatures);
slider->setOrientation(Qt::Horizontal);
slider->setMinimum(0);
slider->setMaximum(16);
connect(slider, SIGNAL(valueChanged(int)), this, SLOT(zoomBarAct(slider->value())));

Here is the zoom function, which I have declared within the private slots section in the header file:

void MainWindow::zoomBarAct(int zoom)
{
    float factor = static_cast<float>(zoom) / 4;
    getCurrentImageArea()->zoomImage(factor);
    getCurrentImageArea()->setZoomFactor(factor);
}

edit for function declaration (other functions after private slots omitted):

private slots:
     void zoomBarAct(int zoom);

Upvotes: 1

Views: 210

Answers (1)

Nikos C.
Nikos C.

Reputation: 51880

This:

SLOT(zoomBarAct(slider->value()))

doesn't make sense. You need to specify the name of the slot:

connect(slider, SIGNAL(valueChanged(int)), this, SLOT(zoomBarAct(int));

However, you are using Qt4-style signal/slot connections. If you switch to modern, Qt5-style syntax, these errors will be caught at compile time. Use this instead, which is much safer and guaranteed to never produce these types of runtime errors, since everything is checked during compilation:

connect(slider, &QSlider::valueChanged, this, &MainWindow::zoomBarAct);

Upvotes: 4

Related Questions