PDA

View Full Version : Start Qt application as Windows Service



^NyAw^
9th May 2008, 18:17
Hi,

I'm trying to start a Qt application with the help of a Windows Service.

The service gets the exe of the application on Windows Registry and starts it without any window.

The problem is that the application is not started. I've tryied to change the application that is started fot "cmd.exe" and it starts correctly.

Is there any problem on starting the application without the main window? -> The application has a main window but the service force it to start without it.

Thanks,

wysota
9th May 2008, 19:53
Maybe you have some path related problem?

^NyAw^
9th May 2008, 20:44
Hi,

No, the path is correct. I have changed the "cmd.exe" to "myApp.exe" on the app dir and it starts without window. But if "myApp.exe" is really my Qt app it don't work.

Thanks,

wysota
9th May 2008, 21:10
I meant maybe your application needs some files which it can't find and crashes before you have a chance to check it out.

^NyAw^
9th May 2008, 22:19
Hi,

The application starts if I start it by double clicking on windows explorer.

Maybe the application don't recive window events because the service starts the application without the main window?
Some time ago I programmed an application using MFC and a service that start it as this new application but the MFC application starts without showing the main window and the new Qt application don't start.

Thanks,

wysota
9th May 2008, 22:22
The application starts if I start it by double clicking on windows explorer.
This doesn't mean anything. The current working directory might be set differently.

^NyAw^
9th May 2008, 22:34
Hi,

The application try to read a config file but removing all this code and only setuping the gui with "ui.setupUi(this);" don't work.

I have added a little code on main.cpp that writes "Hello" on a file. It works executing it but not starting by the service.

Thanks,

wysota
9th May 2008, 22:49
Try compiling and running a non-Qt app like this one:


int main(){
while(1);
return 0;
}

If it works, try adding a QCoreApplication and then a QApplication. Observe what happens in each.

^NyAw^
10th May 2008, 12:23
Hi,

I compiled the simple application and it starts.
Then I created a simple Qt console application that uses QCoreApplication and it is not started by the service.

Thanks,

^NyAw^
10th May 2008, 13:04
Hi,

I copied the Qt libs on the application dir and the QCoreApplication starts.
Then I tryied to create a QApplication and it starts.
Finally tryied my application and starts.
So, I think that when start the application by a Windows Service, the libs must be on the "system32" dir or on the same dir of the application.

Thanks wysota,

^NyAw^
10th May 2008, 15:21
Hi,

The QTDIR path is set as User variable on Windows, so if the service is started as "LocalSystem" it don't have QTDIR path so when try to start my application don't work.

So one solution could be to set the QTDIR on the Path of the system instead of the path of the current user.
Second solution is to copy the Qt libs into the "system32" folder where are the system libs.
Third solution is to copy the Qt libs on the application directory.

:)

wysota
10th May 2008, 16:43
As I said - a path problem. Your libs must be accessible, regardless of system configuration. The only safe place to put them is system32 directory.

^NyAw^
10th May 2008, 17:23
Hi,

Thanks for help,