PDA

View Full Version : Release mode does not work properly with .bin file opening



Lonatico
27th September 2013, 02:24
Hello,

I asked a question sometime back, and none answered :(, I managed to solve the problem by myslef but now I have no idea, and google can't help me much either.

The problem is, my code works fine when I run on debug mode, it opens my .bin files I need to open, perfect.

Although when I try to run on release mode (which I need so I can send the work to my teacher to test and grade) it runs everything alright, except for the file manipulation (opening .bin files in this case), it just won't open my files, I have no ideia why. And yes, the .bin files are on the same directory, I'm trying with the right name too, but it always returns NULL if I check the file pointer.

I'm using the basic stdio.h, so fopen is the opening function, FILE *arq is my pointer, but I can't manage to make it work on release mode. I think there is some library link missing, or something like that, though I don't know exactly, because I'm still a beginner on this subject.

Hope you can understand the question, if you can't, please tell me what you need in a more clear way, so that I can explain, and understand what is wrong.

wysota
27th September 2013, 06:56
I'm using the basic stdio.h, so fopen is the opening function, FILE *arq is my pointer
What is the reason you are asking this question on a Qt forum then?

ChrisW67
27th September 2013, 08:07
Not that this has anything to do with Qt, but if fopen() cannot find the file it will return NULL and set errno to one of many values outlined in the man page for open(2). If you are using a relative path for the file, e.g. "file.bin" and not "/full/path/to/file.bin", then make sure the current working directory of the process is where you think it is.

If you are building/running your non-Qt program from Qt Creator on Windows (a wild guess) then the default working directory for a release executable is different to that for a debug build.

Lonatico
27th September 2013, 14:24
What is the reason you are asking this question on a Qt forum then?
Because with everything else works fine. I have done some code in Codeblocks and the fopen functions work fine, it is only with Qt .exe in release mode that this is happening, so I wondered if there was no problem concerning Qt itself. I'm sorry if I asked in the wrong place, moderators feel free to delete this thread if you think it does not apply to the forum :(


Not that this has anything to do with Qt, but if fopen() cannot find the file it will return NULL and set errno to one of many values outlined in the man page for open(2). If you are using a relative path for the file, e.g. "file.bin" and not "/full/path/to/file.bin", then make sure the current working directory of the process is where you think it is.

If you are building/running your non-Qt program from Qt Creator on Windows (a wild guess) then the default working directory for a release executable is different to that for a debug build.

It seems to be on the right place. Yes I'm using Windows. I'm placing the .bin files inside the release directory, where the .exe is.

anda_skoa
27th September 2013, 19:20
Because with everything else works fine. I have done some code in Codeblocks and the fopen functions work fine, it is only with Qt .exe in release mode that this is happening, so I wondered if there was no problem concerning Qt itself.

All information we have suggests that you are not using Qt. So even if there were a problem in Qt itself, which is highly unlikely since many others would be impacted as well and no such reports have come up, there would still be no relation to your problem.

If you are using Qt somehow then it would be helpful to know what of Qt you are using.

Cheers,
_

ChrisW67
29th September 2013, 21:17
It seems to be on the right place. Yes I'm using Windows. I'm placing the .bin files inside the release directory, where the .exe is.

What does that have to do with the current working dierctory of the running process? See getcwd() C library function.
Have you checked the return codes from fopen()?

Just so we are clear, you are using a non-Qt IDE to write unspecified non-Qt, generic C code, compiled with an unspecified compiler for Windows. That is why we are asking what this has to do with Qt.