c++qtstatusbaruistatusbarqstatusbar

SLOT for statusbar->messageChanged() QT


I've problem with QT statusbar. I want to recive and process changeMessage from statusbar, bo I have problem with slot. How I should write correct slot or how to use connect function correct, with which I've problem too.

file.cpp

connect(statusbar, SIGNAL(messageChanged(const QString &message)), this, SLOT(func1(const QString &message)));

and on the bottom

void file::func1(const QString &message)
{
    statusBarElements->at(0)->setText(statusBarTextElements->at(0));
}

file.h

private slots:

void func1(const QString &message);

And I've recived the message

QMetaObject::connectSlotsByName: No matching signal for func1(QString)

Solution

  • If you are using Qt5 you don't need the SIGNAL and SLOT macros in the connect.

    connect(statusbar, &QStatusBar::messageChanged, this, &file::func1);
    

    This will fail at compile time and give you an error message if the signatures are incompatible.

    Edit: As @G.M. stated in the comments QMetaObject::connectSlotsByName: No matching signal for func1(QString) is an error Qt gives when one tries to use a slot as a signal.