Hi, I'm just wondering what the difference between the Qt documentation example:
signalMapper
->setMapping
(taxFileButton,
QString("taxfile.txt"));
signalMapper
->setMapping
(accountFileButton,
QString("accountsfile.txt"));
signalMapper
->setMapping
(reportFileButton,
QString("reportfile.txt"));
connect(taxFileButton, SIGNAL(clicked()),
signalMapper, SLOT (map()));
connect(accountFileButton, SIGNAL(clicked()),
signalMapper, SLOT (map()));
connect(reportFileButton, SIGNAL(clicked()),
signalMapper, SLOT (map()));
signalMapper = new QSignalMapper(this);
signalMapper->setMapping(taxFileButton, QString("taxfile.txt"));
signalMapper->setMapping(accountFileButton, QString("accountsfile.txt"));
signalMapper->setMapping(reportFileButton, QString("reportfile.txt"));
connect(taxFileButton, SIGNAL(clicked()),
signalMapper, SLOT (map()));
connect(accountFileButton, SIGNAL(clicked()),
signalMapper, SLOT (map()));
connect(reportFileButton, SIGNAL(clicked()),
signalMapper, SLOT (map()));
To copy to clipboard, switch view to plain text mode
connect(signalMapper,
SIGNAL(mapped
(QString)),
connect(signalMapper, SIGNAL(mapped(QString)),
this, SLOT(readFile(QString)));
To copy to clipboard, switch view to plain text mode
As opposed to having something like this would be?:
button.h
{
Q_OBJECT
public:
explicit Button
(QWidget *parent
= 0);
Button
(QString sName
) : m_sName
(sName
) {}
signals:
void ButtonClicked
(QString m_sName
);
}
class Button : public QWidget
{
Q_OBJECT
public:
explicit Button(QWidget *parent = 0);
QString m_sName;
Button(QString sName) : m_sName(sName)
{}
signals:
void ButtonClicked(QString m_sName);
}
To copy to clipboard, switch view to plain text mode
otherfile.cpp
{
//somewhere init something like 20 button classes.
void class
::class_sSlot(QString name
) {
if(name == "a")
{
//do something
}
else if(name == "b")
{
//do something
}
//...etc for remaining 18 comparisons
}
{
//somewhere init something like 20 button classes.
void class::class_sSlot(QString name)
{
if(name == "a")
{
//do something
}
else if(name == "b")
{
//do something
}
//...etc for remaining 18 comparisons
}
To copy to clipboard, switch view to plain text mode
Would there be a speed advantage of doing it the way it's presented in the Qt documentation over the second example?
Bookmarks