Fixed crashes on signal emittion

This is caused by two bugs:
1) QMetaObject::activate first argument must be the return value
2) The next arguments should be void* to the actual datatype contained inside the QVariants
   and not QVariant*. In other words given "a" of type QVariant we should use a.constData()
   and not &a
This commit is contained in:
Filippo Cucchetto 2016-04-09 14:56:11 +02:00
parent 49c571ecaa
commit 0e1ab9e5ad
1 changed files with 3 additions and 3 deletions

View File

@ -25,9 +25,9 @@ bool DosQObjectImpl::emitSignal(QObject *emitter, const QString &name, const std
Q_ASSERT(name.toUtf8() == method.name()); Q_ASSERT(name.toUtf8() == method.name());
std::vector<void *> arguments(args.size(), nullptr); std::vector<void *> arguments(args.size() + 1, nullptr); // +1 for the result at pos 0
auto func = [](const QVariant & arg) -> void * { return (void *)(&arg); }; for (size_t i = 0; i < args.size(); ++i)
std::transform(args.begin(), args.end(), arguments.begin(), func); arguments[i+1] = const_cast<void*>(args[i].constData()); // Extract inner void*
QMetaObject::activate(emitter, method.methodIndex(), arguments.data()); QMetaObject::activate(emitter, method.methodIndex(), arguments.data());
return true; return true;
} }