I have found the answer in [here][1]. But a new problem is raised.

I put a breakpoint on the line **QgsApplication app(argc, argv, true)** and the debugger pops up this:

[![enter image description here][2]][2]

And at the end of the program, when the line **return app.exec();** run, this warning is displayed on the console.

> QApplication::exec: Please instantiate the QApplication object first

PS: I explain the problem completely [here][3].


  [1]: https://gis.stackexchange.com/a/365166/134178
  [2]: https://i.sstatic.net/D1LPu.png
  [3]: https://gis.stackexchange.com/q/397252/134178