QCanDbcFileParse load error
-
@dhagrow Why don't you do what the documentation suggests?
https://doc.qt.io/qt-6/qcandbcfileparser.html#parse
"If the parsing failed, call the error() and errorString() methods to get the information about the error." -
@jsulm said in QCanDbcFileParse load error:
"If the parsing failed, call the error() and errorString() methods to get the information about the error."
OP already does!
if not parser.parse(dbc_file): sys.exit(f"QCanDbcFileParser.parse: {parser.errorString()}") // Output: QCanDbcFileParser.parse: No such file or directory
I think OP is asking: He shows
QFile::open()
ing the file correctly and shows its contents, so why does he get a "no such file or directory" fromparser.parse(dbc_file)
on same file path? I don't know.@dhagrow
FWIW, bool QCanDbcFileParser::parse(const QString &fileName)Note: This method expects the file contents to be encoded in UTF-8. If the file has a different encoding, decode it first, and use parseData() to extract the DBC information.
You might try passing your
f.readAll()).decode()
to bool QCanDbcFileParser::parseData(QStringView data) to see whether that succeeds? I do not know how that relates to a "no such file" failure fromQCanDbcFileParser.parse()
. -
@JonB said in QCanDbcFileParse load error:
OP already does!
You're right, did not see that in the string formatting :-)
-
@jsulm said in QCanDbcFileParse load error:
@SGaist As far as I can see OP is passing a path to the file
Indeed, I misread the reading/printing and parse call !
@dhagrow, @JonB has a point with regard to UTF-8.
Also, on which OS are you seeing this issue ?
-
@JonB said in QCanDbcFileParse load error:
@SGaist said in QCanDbcFileParse load error:
Except that error "no such file or directory" does not sound like that, does sound like it's not finding the file. Or a strange message.
Indeed, I was just adding more weight with regard to using parseData which was related to my original question about it although it was mainly because I misread the code sample.
-
QCanDbcFileParser.parseData()
does indeed work! Thanks for pointing that out, I hadn't noticed that method. I'm not sure why the encoding would matter. The contents are ASCII, which should be decoded by UTF-8 with no problem.Nothing obvious strikes me from the source here, but I guess
QString
is not included in PySide, so I can't easily check.It does seem like there should be a better error there, but this solves my immediate problem, and hopefully helps anyone else that runs into it. For the record, I'm on Linux. Thanks again!
-
-
@dhagrow
Yes,parseData()
will work, the question is whyparser.parse(dbc_file)
does not seem to open the file from its name. Just try makingdbc_file
be the correct full path to the file (not just plain"dbc_file"
) and check whether that makes a difference? -
I think I found the problem. I noticed that there's an overload for
QCanDbcFileParser.parse
that takes a QStringList. It turns out that it works if I pass in['test.dbc']
! I then tried['t']
and['.']
and get the same errors I was getting above. It seems PySide is wrapping the overloaded method. -
@dhagrow
But I thought you started from passing a sting, like"dbc_file"
. That should match parse(fileName) wherefileName – str
. I don't know exactly what you tried? Where did you getdbc_file
varibale value from? Be careful of you prompted the user for it with QFileDialog.getOpenFileName(), that returns a list, not just the filename.I don't know whether you are now saying you are sorted or not.
-
Yes, I am sorted. The
QCanDbcFileParser.parseData
option was all I needed, but I see that I can also useQCanDbcFileParser.parse
if I pass in the file name in a list."dbc_file"
came from a command-line argument, so effectively I was making the call like:parser.parse("test.dbc")
. That appears to treat the string like a list, so withtest.dbc
it would try to opent
, and with./test.dbc
it would try.
, both of which align with the errors I was seeing. I now see that I can make the call like:parser.parse(["test.dbc"])
, which works.Basically, what I am saying is that PySide is not calling
QCanDbcFileParser::parse(QString)
. It is actually callingQCanDbcFileParser::parse(QStringList)
.