PDA

View Full Version : fgets in Qt(Gui mode)



summer_of_69
9th June 2009, 13:36
Hi All,

I am facing one problem.I have one existing code written in C ,I want to use Qt functionality(GUI) to make it more user friendly .
Problem:-
One part of the code contains fgets() operation ,which is called when certain file is missing and user has to specify file path in command window("cmd" in windows).
I have compiled the code using qt application(GUI) mode,but it is not calling the command window which is leading my program to crash.

PS:- It is working absolutely fine in CONSOLE Mode.

Can anyone help me with this?:confused:

Thanks in advance.

AcerExtensa
9th June 2009, 15:37
why don't you let user specify file path in GUI? look at QFileDialog...

nish
9th June 2009, 15:48
replace fgets with QInputDialog

summer_of_69
10th June 2009, 06:08
Thanks for your quick reply.
I can use QFileDialog,QInputDialog but I don't want to change the existing code. Is there some way to call cmd window automatically as soon as program encouters fgets() ?
How it works absolutely fine in "Qt Console" mode?

Even Qt GUI mode contains QtCore libraries , there must be some some way out of this mess.I think I am missing some thing.:confused:

summer_of_69
10th June 2009, 10:04
I think GUI thread is blocking console application. I know it can be invoked using QProcess::startDetached("cmd.exe") ,or I can use QInputDialog/QFileDialog.

Limitation :- I can't do changes inside C code since they are using fgets() throughout the application to prompt user for input.

Problem:- I want to handle fgets using GUI thread,to get the same feel as if I have compiled the code for Qt cosole application.

Thanks.

nish
10th June 2009, 10:52
why cant u change the code??

summer_of_69
10th June 2009, 11:09
It's a 18 years old legacy code written in "C" contains 2,86063 lines with fgets in more than 100 places.
I have already created GUI for that with all interface,if no other option I will have to go for this bull work.Before this I want to be 100% sure that there is no other way than to change the whole code and replace it with "QInputDialog/QFileDialog" etc...

nish
10th June 2009, 11:27
i dont have exp in console apps... and your situation is unique...

if i were u then i would just search and replace the fgets as


search
fgets(char*,xx,xx,xx);
replace with
myFgets(char*,xx,xx,xx);

its a very easy thing and u dont have to do anything if u use any text editor..

then make your function
myFgets(char* str,xx,xx,xx)
{
QString file=QInputDialog/QFileDialog;
str=(convert string char by char);
}

summer_of_69
10th June 2009, 11:46
Sorry I didn't explain the whole scenerio. My application has two modes "GUI" and "Console" ,user can opt for any using Config file(which I have yet to create). Application has to read that file and load the application accordingly(console/gui mode).

Now my problem is how can I do this? I don't want two different exe for console and GUI :confused:
That's why I am searching for some solution to control console using GUI so that only one exe is enough.