I've been playing around with QT5 for Android, I've been struggling a bit with extending an existing class so I can play a sound anytime I click on a radio button that has been promoted.
I'm using the standard QT APP template to get started,
This is what I have so far: radiowclick.h:
#ifndef RADIOWCLICK_H
#define RADIOWCLICK_H
#include <QObject>
#include <QWidget>
#include <qradiobutton.h>
class RadioWClick : public QRadioButton
{
Q_OBJECT
Public:
RadioWClick(QWidget *parent = 0);
signals:
void clicked();
private slots:
void PrivateClicked();
};
#endif // RADIOWCLICK_H
radiowclick.cpp:
#include "radiowclick.h"
#include <QtMultimedia/qsound.h>
RadioWClick::RadioWClick(QWidget *parent) :
QRadioButton(parent)
{
connect(this, SIGNAL(clicked()), this, SLOT(PrivateClicked()));
}
void RadioWClick::PrivateClicked()
{
QSound::play(":/sounds/ButtonClick.wav");
}
main.cpp: #include "radiowclick.h"...
Everything compiles fine, when I use vanilla sockets and slots I get the clicking sound, but with the promoted radiobuttons and the private slot i have no joy.
Thanks for your help! :)
I think what's happening is you're overwriting the
connect
signal defined inQAbstractButton
which is a base ofQPushButton
.Try removing your definition of
clicked()
and connecting your signalPrivateClicked()
to the base classclicked()
signal.Some code:
And the implementation
NOTE: I have not tested this code. Use at your own risk.