PDA

View Full Version : QTestLib: check if the signal has a std::string type



tarod
14th December 2012, 09:30
Hi,

I found the next code reading the documentation:


QSignalSpy spy(myCustomObject, SIGNAL(mySignal(int, QString, double)));

myCustomObject->doSomething(); // trigger emission of the signal

QList<QVariant> arguments = spy.takeFirst();
QVERIFY(arguments.at(0).type() == QVariant::Int);
QVERIFY(arguments.at(1).type() == QVariant::QString);
QVERIFY(arguments.at(2).type() == QVariant::double);

But I'm having many problems when I want to check if the signal has a std::string type.

Any idea?

Thanks.

wysota
14th December 2012, 09:47
Did you register std::string with QVariant?

tarod
14th December 2012, 10:06
Yes, I did that.

Now I have the line QList<QVariant> arguments = spy.takeFirst(); working right.

Following with the code, how can I convert "arguments.at(1)" (if at(1) is a std::string) to std::string?

Using QVariant, the method toString() is returning an empty string, so I cannot use toString().toStdString().

wysota
14th December 2012, 10:11
QVariant var = ...;
std::string str = var.value<std::string>();

tarod
14th December 2012, 10:20
I've just find the same solution.

Thanks anyway!