QFile Problem
-
I try to write a file with the QFile library with the following code like it is in the QT documentation..
QFile file("out.txt"); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) return; QTextStream out(&file); out << "The magic number is: " << 49 << "\n";
But it complains about the file.open part.
-
@LainOnTheWired said in QFile Problem:
But it complains about the file.open part.
you need to be more specific
-
It says canditate function not vaible: no knowen conversation from int to OpenMode(aka QFlags<QIODevice OpenModeFlag>) for 1st argument. Is this enough or do you need more ?
-
@LainOnTheWired
did you include QFile ?#include <QFile>
-
Yes it is included.
-
Yes thats it with include<QIODevice> it works thanks so much :) and you need to include #include <qtextstream.h> for the stream too.
-
@LainOnTheWired said in QFile Problem:
Yes thats it with include<QIODevice> it works thanks so much :) and you need to include #include <qtextstream.h> for the stream too.
That's very odd. The QFile header should already contain
#include <QIODevice>
...Has the QFile header been modified?
-
@VRonin
That's precisely what I meant! Perhaps "worried" was too strong a word :) The error message suggested to me that theQFlags
were not working correctly with the|
operator, hence my guess about not having the correct#include
. I intended to suggest that the OP should pursue why this appeared to be the case. -
It is the fault of KDevelop, if i have only the QFile include it puts this error message but if i compile the program it works correctly. The error message is wrong. Very strange and no i have not modified the header file.
-
The error message is wrong.
Up to you, but the compiler error/warning message cannot be "wrong". If it warns it means what it says in terms of not having the definition, compilers don't invent error messages. It may work at runtime if it's only a warning and the semantics actually allow an
int operator|()
to work in this case, which it probably does.Likely perhaps: if you have other
#include
s (e.g. from "KDevelop") prior (or possibly post) to your#include <QFile>
that might affect definitions/behaviour and cause your issue.... -
@JonB I think the error is not coming from the compiler but from the Clang Code Model which is known for producing many false positives.
@LainOnTheWired You can try to disable Clang Code Model