2

I have an example that use

QApplication app(argc,argv);
QStandardItemModel* model = new QStandardItemModel(r,c,&app);

But in my program I have

QScopedPointer<QApplication> app(createApplication(argc, argv));
QStandardItemModel* model = new QStandardItemModel(r,c,&app); //ERROR: no matching function

How to use this QScopedPointer without error?

demonplus
  • 5,613
  • 12
  • 49
  • 68
meolic
  • 1,177
  • 2
  • 15
  • 41

3 Answers3

2

Use app.data(). Though it is very unusual to create the QApplication on the heap...

cmannett85
  • 21,725
  • 8
  • 76
  • 119
2
QScopedPointer<QApplication> app(createApplication(argc, argv));
QStandardItemModel* model = new QStandardItemModel(r,c,app.data());
zabulus
  • 2,373
  • 3
  • 15
  • 27
1

hope to be useful

#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;
}
sam
  • 1,363
  • 1
  • 20
  • 32