0

I'm making a Qt application in C++ and right now I'm having trouble with a constant.

I use to have this code that worked

myMainWindow::myMainWindow()
{
  ...
}

//-----------------------------------------------------------------------------
myMainWindow::~myMainWindow()
{
  delete this->Internals;
}

//-----------------------------------------------------------------------------
void myMainWindow::on_Users_pressed() {
  pqPythonManager* manager = pqPVApplicationCore::instance()->pythonManager();

  manager->executeScriptAndRender("/path/to/file/users.py");
}

But I want to put the path to file in a constant because it repeats in several places

#include <iostream>
using namespace std;

const string PATH = "/path/to/file/";

class myMainWindow::pqInternals : public Ui::pqClientMainWindow
{
};
myMainWindow::myMainWindow()
{
  ...
}

//-----------------------------------------------------------------------------
myMainWindow::~myMainWindow()
{
  delete this->Internals;
}

//-----------------------------------------------------------------------------
void myMainWindow::on_Users_pressed() {
  pqPythonManager* manager = pqPVApplicationCore::instance()->pythonManager();

  manager->executeScriptAndRender(PATH + "users.py");
}

But I'm getting the error

error: no viable
      conversion from 'std::__1::basic_string<char>' to 'const QString'
  manager->executeScriptAndRender(PATH + "users.py");
                                  ^~~~~~~~~~~~~~~~~~~~~~
/Applications/Qt/5.9.9/clang_64/lib/QtCore.framework/Headers/qstring.h:219:5: note:
      candidate constructor not viable: no known conversion from
      'std::__1::basic_string<char>' to 'QChar' for 1st argument
    QString(QChar c);

How can I make this work?

alo gon
  • 79
  • 3
  • 7

0 Answers0