[SOLVED] Qt C++ signal only invoked by other Qt function is not received in QML
-
Hello, I have a problem receiving a signal from a QtObject derived class in QML. The signal is fired up correctly, what it tested in the C++ part. But the slot in QML seems not to receive it. The signal is emitted in a slot that gets it's data from another class through a signal. The classes are givent to QML through setContextProperty. I can also use public functions in that class through Q_INVOKABLE. When I start such a function, I can receive emitted signals in QML. But it does not work, when the slot/function is called by another signal out of Qt.
Here is my code. The class should normaly handle SSL errors and then show a QML dialog with information about it. The signal showSSLDialog(...) should fire up the dialog, but seems to be not received in QML. As written before, in Qt it works.
header:
@
class OcNetwork : public QObject
{
Q_OBJECT
public:
explicit OcNetwork(QObject *parent = 0);signals:
void showSSLDialog(QVariantMap sslError, QVariantList certs);public slots:
void slotAuthenticationRequired(QNetworkReply* rep,QAuthenticator * authenticator);
#ifndef QT_NO_OPENSSL
void sslErrors(QNetworkReply *rep,const QList<QSslError> &errors);
#endifprivate:
QSettings settings;
QString formatDigest(QByteArray digest, QString devider);};
@cpp:
@
void OcNetwork::sslErrors(QNetworkReply *rep, const QList<QSslError> &errors)
{
QString errorString;
foreach (const QSslError &error, errors) {
qDebug() << error.errorString();
if (!errorString.isEmpty())
errorString += ". ";
errorString += error.errorString();
}QVariantMap sslError; sslError["errorString"] = errorString; sslError["certChainCount"] = rep->sslConfiguration().peerCertificateChain().count(); QVariantList certs; foreach (const QSslCertificate &cert, rep->sslConfiguration().peerCertificateChain()) { QVariantMap certdata; certdata["subjectO"] = cert.subjectInfo(QSslCertificate::Organization); ................. certs << certdata; } rep->ignoreSslErrors(); emit showSSLDialog(sslError, certs);
}
@The slot is called by signal from QNetworkAccessmanager. And all that works fine. Only the singal showSSLDialog() is not recognized by QML.
This is with Qt 4.7.4 on Meego Harmattan 1.2 (Nokia N9)
-
Hello,
You need to connect QT signal to QML function in main.cpp:
connect(&QTClass, SIGNAL(QTsignal), QMLViewObject, QMLFunction);
"link":http://developer.nokia.com/Community/Wiki/Connecting_Qt_signal_to_QML_function to code example...
-
Connecting it through this way instead of setContextProperty leads to the same result. Also I used setContextProperty for every other class before, and it worked without any problems.
When I emit the same signal in the class, where QNetworkAccessmanager is called, which than emits SSLErrors, which is connected to a slot in the same class, then it works. But when I connect the nam signal to a slot in another class, then it works up to the point, when the last signal should reach QML.
-
I tried a bit more around. When the signal chain starts in the same class which emits the final signal to show the dialog in QML, then it works. But if the chain jumps to another class, everything works, except the last final signal to show the QML dialog.
-
Ahhhhh, I got it. The whole time I had a error in reasoning. I missed that I was working with two different instances of the same class. I emitted the signals in the one instance and was waiting for the resulting signal from the other instance. Sure, that can not work.....