0

从可以从 javascript 访问的插槽函数中,我返回一个 QVariantMap,因为我希望将数据转换为包含一些原语的 JavaScript 对象。

代码如下所示:

QVariantMap MyObject::createResults()
{
  QVariantMap ret;
  ret["num"] = 23948;
  ret["str1"]   = QString("bla");
  ret["str2"]   = QString("blub");
  return ret;
}

调用脚本如下所示:

  var myObj = new MyObject();
  var res = myObj.createResults();
  api.cout("typeof(res);      = " +typeof(res));      
  api.cout("typeof(res.num);  = " +typeof(res.num));  
  api.cout("typeof(res.str1); = " +typeof(res.str1)); 
  api.cout("typeof(res.str2); = " +typeof(res.str2)); 

并产生以下输出:

typeof(res);      = object
typeof(res.num);  = object
typeof(res.str1); = string
typeof(res.str2); = string

在 c++ 方面我需要做typeof(res.num)什么number

使用的版本是 Qt 4.8.2

4

0 回答 0