2

我有一个使用的例子

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?

4

3 回答 3

2

使用app.data(). 虽然QApplication在堆上创建是非常不寻常的......

于 2012-08-22T09:56:24.217 回答
2
QScopedPointer<QApplication> app(createApplication(argc, argv));
QStandardItemModel* model = new QStandardItemModel(r,c,app.data());
于 2012-08-22T09:56:42.360 回答
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;
}
于 2015-07-28T10:00:11.580 回答