Reputation: 1480
I'm building an application which needs to read and write from several files. I've noticed that when trying to write to these files when running from inside the Qt Creator I get the message "QIODevice::write: device not open", but if I try running the application standalone it works fine and the files do write.
In either circumstance, the application can read the files fine, the only issue is with trying to write the file.
This happens whether the application is running in debug or released versions, or whether or not Qt Creator is running in administrative mode or not.
Here is a code snippet of a particular instance in which I'm trying to write a file:
void Window::saveConfig(Qt::Key binds[])
{
QFile file(QDir::currentPath()+"/Data/config.dat");
file.open(QIODevice::ReadWrite | QIODevice::Text);
QTextStream out(&file);
for (int x = 0; x < 6; x++)
{
QString s = QKeySequence(binds[x]).toString();
out << s +"'\n";
}
file.close();
}
Just to reiterate: The application can write the files fine outside of qt creator, just inside it doesn't work
Upvotes: 0
Views: 1386
Reputation: 8242
QDir::currentPath() returns the current directory. In Qt Creator, click Projects, then click the Run tab, and set the current directory to whatever you like. By default (at least on my machine) it's set to the project's build folder.
Upvotes: 1