我有一个使用的例子
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?
QScopedPointer<QApplication> app(createApplication(argc, argv));
QStandardItemModel* model = new QStandardItemModel(r,c,app.data());
使用app.data()
。尽管在堆上创建QApplication
是非常不寻常的。。。
希望成为有用的
#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;
}