PDA

View Full Version : need of some help



srikanthch
27th November 2008, 10:22
Hi.

I am new to the Qt environment,developing an application in Qt 4.4 under windows platform.i need my application to run everytime when my system starts or reboots.for this we have to keep the application files(.exe or .ini ) into the windows registry.can i have some code snippets for this application?

Thanks & Regards,
Srikanth

high_flyer
27th November 2008, 11:28
an i have some code snippets for this application?
snippets of code of doing what?
We can't solve your problem for you, but we can try and help you with specific problems.
If you say what it is you tried and it didn't work for you, we might be able to help you with that.

srikanthch
27th November 2008, 11:49
Hello,

My application should run automatically whenever i started my system.For that,we can use Qsettings class and writeEntry() methods to load my application exe file into the windows registry.my code is as follows:


QSettings settings;
settings.writeEntry("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\Curr entVersion\Run","Notepad");
settings.writeEntry("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\Curr entVersion\Run\notepad.exe",true);



But it is not working.thats why i need some code...

high_flyer
27th November 2008, 12:02
the code you posted is registering notepad.exe.
Is your application named notepad.exe?
If it is, I would strongly suggest to use a different name, since windows has its own notepad program.
Don't forget that the path to the application needs to be correct as well.

Any way, an easy way of doing this is to add you application to the start menu under "autostart".
Would that be an acceptable solution for you?

srikanthch
27th November 2008, 12:16
Thanks for you information,which helped me...
I gave that name for examplet for better understanding.i need to register my application by executing some code in Qt only.So,i am in need of help for that code only.

high_flyer
27th November 2008, 12:38
maybe if you show your real code we might help you better see where the error is.

srikanthch
28th November 2008, 04:56
My code is as follows :

1)

#include<QSettings.h>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QSettings settings;
settings.writeEntry ("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\ CurrentVersion\\Run","C:\Windows\Notepad");
settings.writeEntry("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\ CurrentVersion\\Run\\notepad.exe",true);

re12 w;
w.show();
return a.exec();
}


2)



#include<Qsettings.h>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QSettings settings;
settings.setPath("HKEY_LOCAL_MACHINE\Software\Microsoft","\Windows\CurrentVersion\Run\notepad", QSettings::User);
settings.writeEntry("C:\Windows\Notepad.exe", true);
reg13 w;
w.show();
return a.exec();
}



The above are two types of codes,executing without any errors but the key is not created in the registry editor...

Thanks..

srikanthch
28th November 2008, 07:35
Hi

Whts wrong with this code :::

#include<Qsettings>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QSettings My_settings;
My_settings.insertSearchPath( QSettings::Windows, "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\Curr entVersion\Run" );



/*THIS IS ONE WAY OF REGISTERING THE KEY INTO REGISTRY EDITOR */

My_settings.writeEntry("\Notepad","C:\Windows\Notepad.exe");
My_settings.writeEntry("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\Curr entVersion\Run\notepad",true);


/*THIS IS ANOTHER WAY OF REGISTERING THE KEY INTO REGISTRY EDITOR */

/* My_settings.setPath("Microsoft", "Windows", QSettings::User);
My_settings.writeEntry("/CurrentVersion/Run/notepad.exe", true);*/


reg w;
w.show();
return a.exec();
}

srikanthch
1st December 2008, 05:09
Hi Guys,

I got the solution for my task.the code is as follows:



#include<Qsettings>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QSettings My_settings;
//Defining My_settings under QSettings Class
My_settings.setPath("Microsoft", "Windows", QSettings::Global);
//Searching the required path
My_settings.writeEntry("\CurrentVersion\Run\Notepad","C:\\WINDOWS\\NOTEPAD.EXE");
//Entering the key into the path

reg w;
w.show();
return a.exec();
}