Skip to content

How to get list results from QVariant #97

Description

@RuoyanMeng

Hi, I am using pythonQt to embed python code in my C++ code, I create a python function as the example did, but my return value is a list, and I couldn't fetch the list value after calling the function
context.evalScript("def multiply(a,b):\n return [a,b];\n");
QVariantList args;
args << 42 << 47;
QVariant result = context.call("multiply", args);

Could you give some idea on how to get the result when the return value is a list?

Activity

  1. usiems commented on Feb 17, 2023

    @usiems
    Contributor
    QVariantList resultList = result.toList();
    int a = resultList[0].toInt();
    int b = resultList[1].toInt();
    

    This is without any type checking, but I guess the important part is the toList() method. Simply have a look at the interface of QVariant.

  2. RuoyanMeng commented on Feb 17, 2023

    @RuoyanMeng
    Author
  3. locked and limited conversation to collaborators on Feb 17, 2023
  4. converted this issue into a discussion #98 on Feb 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions