[Solved] Problem with QFIle
-
What are the lines above this code?? It says that it's missing something BEFORE this QFile!! Not after it, or on this line. It just encounters code that should be preceded by a ; The compiler is unable to determine where the ; is missing.
-
@bool Hex::LoadHexFile(void)
{
int iRet;
char HexRec[255];QFile *file = new QFile;
@...then the rest of the file.
-
Ok,
Your QFile may not be without arguments!
so
@
QFile * file = new QFile(this); // Is valid
QFile * file = new QFile (SomeFileString); // Is Valid
QFile * file = new QFile; // NOT valid!!
@
You can also see that Qtcreator itself signals the problem by not highlighting the QFile after the new!! -
Sorry... but it is not working. I still get the same error. The only way I found was to make file a static QFile.
-
[quote author="koahnig" date="1383309034"]
@
{
QFile file = new QFile (this);
HexFilePath = QFileDialog::getOpenFileName(0, ("Open File"), NULL, ("hex File(.hex)"));
HexFilePtr=file;
} // focus lost to pointer file
HexFilePtr->setFileName(HexFilePath);
@
[/quote]Did you use this example above or something similar?
-
I use the example above. I also tried other things.
Right now I have declared static QFile *file and then assign it to HexFilePtr. This is the only way to make things work right now.
I don't think we can pass "this" into QFile constructor
-
bq. Ok,
Your QFile may not be without arguments!
so@QFile * file = new QFile(this); // Is valid
QFile * file = new QFile (SomeFileString); // Is Valid
QFile * file = new QFile; // NOT valid!!@imho that's not true, see QFile class definition: it has a default constructor with no arguments even if is not listed in doc
bq. I don’t think we can pass “this” into QFile constructor
yes you can and the QFile object will be distroyed automatically by its parent destructor
-
is bool Hex::LoadHexFile(void) declared as static in class definition?
-
Thanks for the infos.
bool Hex::LoadHexFile(void) is public and is not declared static.
Weird really!
-
no, it shouldn't be ... it must work as expected
could you paste your class definition? -
@#ifndef HEX_H
#define HEX_H#pragma once
//#include "stdio.h" #include <stdio.h>
#include <QObject>
#include "QFile"typedef struct
{
unsigned char RecDataLen;
unsigned int Address;
unsigned int MaxAddress;
unsigned int MinAddress;
unsigned char RecType;
unsigned char* Data;
unsigned char CheckSum;
unsigned int ExtSegAddress;
unsigned int ExtLinAddress;
}T_HEX_RECORD;// Hex Manager class
class CHexManager
{public:
unsigned int HexTotalLines;
unsigned int HexCurrLineNo;
bool ResetHexFilePointer(void);
bool LoadHexFile(void);
bool LoadHexFileChannel(void);
unsigned short GetNextHexRecord(char HexRec, unsigned int BuffLen);
unsigned short ConvertAsciiToHex(void VdAscii, void VdHexRec);
void VerifyFlash(unsigned int StartAdress, unsigned int ProgLen, unsigned short crc);//Constructor CHexManager() { //HexFilePtr = NULL; } //Destructor ~CHexManager() { // If hex file is open close it. }
private:
QString HexFilePath;
QFile *HexFilePtr;};
#endif // HEX_H@