我有一个使用
的例子QApplication app(argc,argv);
QStandardItemModel* model = new QStandardItemModel(r,c,&app);
但在我的节目中我有
QScopedPointer<QApplication> app(createApplication(argc, argv));
QStandardItemModel* model = new QStandardItemModel(r,c,&app); //ERROR: no matching function
如何正确使用此QScopedPointer?
答案 0 :(得分:2)
使用app.data()
。虽然在堆上创建QApplication
是非常不寻常的......
答案 1 :(得分:2)
QScopedPointer<QApplication> app(createApplication(argc, argv));
QStandardItemModel* model = new QStandardItemModel(r,c,app.data());
答案 2 :(得分:0)
希望有用
#include <QScopedPointer>
class target
{
public:
int var;
};
class logic
{
public:
QScopedPointer<target> variable;
target* variable2;
};
int main()
{
logic LogicClass;
LogicClass.variable.reset(new target);
LogicClass.variable->var=10;
cout<<LogicClass.variable->var<<endl;
LogicClass.variable2 = new target;
LogicClass.variable2->var = 20;
cout<<LogicClass.variable2->var<<endl;
delete LogicClass.variable2;
return 0;
}