Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qtcollider: QcSignalSpy prevent creating QVariant<QVariant> #5216

Merged
merged 1 commit into from
Nov 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion QtCollider/QcSignalSpy.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ class QcSignalSpy : public QObject {

for (int i = 0; i < _argTypes.count(); ++i) {
QMetaType::Type type = static_cast<QMetaType::Type>(_argTypes.at(i));
args << QVariant(type, argData[i + 1]);
if (type == QMetaType::QVariant) {
// avoid creating a QVariant<QVariant>
args << QVariant(type, argData[i + 1]).value<QVariant>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this is exactly the same, just fewer steps :)

Suggested change
args << QVariant(type, argData[i + 1]).value<QVariant>();
args << argData[i + 1]);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also what I would think, but then it complains that QVariant(void*) is a deleted function.

QcSignalSpy.h:96:40: error: use of deleted function ‘QVariant::QVariant(void*)’
   96 |                     args << argData[i+1];

/usr/include/qt/QtCore/qvariant.h:499:12: note: declared here
  499 |     inline QVariant(void *) = delete;

Does this mean that Qt explicitly forbids "casting" a (void*) to QVariant?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohh i missed that was the type of argData (void**). yeah, this is fine the way it is, i think this would also work:

Suggested change
args << QVariant(type, argData[i + 1]).value<QVariant>();
args << *static_cast<const QVariant*>(argData[i + 1]);

but that's just a hunch.

inline QVariant(void *) = delete; is a constructor for QVariant, when marked with "delete" it means the compiler will forbid calling it.

} else {
args << QVariant(type, argData[i + 1]);
}
}

react(args);
Expand Down
3 changes: 1 addition & 2 deletions QtCollider/widgets/QcWebView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,7 @@ void WebView::toPlainText(QcCallback* cb) const {
void WebView::runJavaScript(const QString& script, QcCallback* cb) {
if (page()) {
if (cb) {
// convert QVariant to string until we deal with QVariants
page()->runJavaScript(script, [cb](const QVariant& t) { cb->call(t.toString()); });
page()->runJavaScript(script, cb->asFunctor());
} else {
page()->runJavaScript(script, [](const QVariant&) {});
}
Expand Down