Qt 4.2.3, compiled statically
MS Visual Studio 2005
In myMainWindow.h
{
Q_OBJECT
public:
myMainWindow
(QWidget *parent
= 0, Qt
::WFlags flags
= 0);
~myMainWindow();
...
private slots:
void on_aboutUs_clicked(bool checked);
...
};
class myMainWindow : public QMainWindow
{
Q_OBJECT
public:
myMainWindow(QWidget *parent = 0, Qt::WFlags flags = 0);
~myMainWindow();
...
private slots:
void on_aboutUs_clicked(bool checked);
...
};
To copy to clipboard, switch view to plain text mode
In myMainWindow.cpp
myMainWindow
::myMainWindow(QWidget *parent, Qt
::WFlags flags
){
ui.setupUi(this);
connect(ui.aboutUs, SIGNAL(clicked(bool)), this, SLOT(on_aboutUs_clicked(bool)));
...
}
myMainWindow::on_aboutUs_clicked(bool checked)
{
}
myMainWindow::myMainWindow(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
ui.setupUi(this);
connect(ui.aboutUs, SIGNAL(clicked(bool)), this, SLOT(on_aboutUs_clicked(bool)));
...
}
myMainWindow::on_aboutUs_clicked(bool checked)
{
QDesktopServices::openUrl(QUrl(tr("http://www.whatever.com/about.html")));
}
To copy to clipboard, switch view to plain text mode
In ui_myMainWindow.h
class Ui_myMainWindowClass
{
public:
...
aboutUs
->setObjectName
(QString::fromUtf8("aboutUs"));
aboutUs
->setGeometry
(QRect(11,
0,
195,
27));
aboutZeiss
->setIcon
(QIcon(QString::fromUtf8(":/myMainWindow/Resources/AboutUs.png")));
class Ui_myMainWindowClass
{
public:
QPushButton *aboutUs;
...
aboutUs= new QPushButton(page_2);
aboutUs->setObjectName(QString::fromUtf8("aboutUs"));
aboutUs->setGeometry(QRect(11, 0, 195, 27));
aboutZeiss->setIcon(QIcon(QString::fromUtf8(":/myMainWindow/Resources/AboutUs.png")));
To copy to clipboard, switch view to plain text mode
As you can see there is not much to it. When the button is clicked, two instances of the URL are opened. I've set breakpoints in the slot and yes indeed it gets called twice. This happens with all ten buttons in the app.
As a work-around, I'm experimenting with using the "released" signal instead of the "clicked" signal.
Bookmarks