You have to use a lambda function:
#include <QApplication>
#include <QDesktopServices>
#include <QPushButton>
#include <QUrl>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QPushButton p("Click me");
QString link = "http://www.google.com";
QObject::connect(&p, &QPushButton::clicked, [&link](){
QDesktopServices::openUrl(QUrl(link));
});
p.show();
return a.exec();
}
or with std::bind()
#include <QApplication>
#include <QDesktopServices>
#include <QPushButton>
#include <QUrl>
#include <functional>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QPushButton p("Click me");
QString link = "http://www.google.com";
QObject::connect(&p, &QPushButton::clicked, std::bind(QDesktopServices::openUrl, QUrl(link)));
p.show();
return a.exec();
}
note:
you need to enable C++11 in Qt, for this review the following question: How to enable C++11 in Qt Creator?, which indicates that you add CONFIG += c++11
in your .pro