Application exception when starting from a service



  • I am relatively new to QT, and found it very useful. However there is something strange in QT. I can't start an QT application from service. It returns c0000135, or access violation.

    EDIT: The service is running as me, so it is definitely not permission issue.

    Tried to debug it and a app stripped to the bone works fine, but the moment I add the line QApplication(argc,argv), it started to happen (without any other code in there).

    Attached is the zip file with the sample application and a service to test it (sorry I hard coded everything so you might need to adjust it to run it correctly). As you can see during QApplication initialization, something happened and none of the printf comes out, if I took it out, everything is fine.

    QT code:
    @#include <stdio.h>

    //#include <QApplication>
    #include <QCoreApplication>

    int main(int argc, char *argv[])
    {
    printf("start v0.1!!\n");
    printf("start v0.2!!!\n");

    FILE *fp = fopen&#40;"c:\\temp\\t.txt","w"&#41;;
    fclose(fp&#41;;
    
    QCoreApplication a(argc, argv);    
    printf("loading\n");    
    return 0;
    

    }
    @

    QT project file:
    @
    QT += core widgets

    TARGET = test
    CONFIG += console
    CONFIG -= app_bundle

    TEMPLATE = app

    SOURCES += main.cpp

    @

    Part of service code (in c#)
    @
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.IO;
    using System.Linq;
    using System.Text;
    using System.Threading;
    using System.Threading.Tasks;

    namespace ConsoleApplicationServiceTest
    {
    class Program
    {
    static void Main(string[] args)
    {
    //Doit();
    //return;

            System.ServiceProcess.ServiceBase[] ServicesToRun;
            // Change the following line to match.
            ServicesToRun = new System.ServiceProcess.ServiceBase[] { new Service1() };
            System.ServiceProcess.ServiceBase.Run(ServicesToRun);
        }
    
        public static void Doit()
        {
            new Thread(() =>
            {     
                var name = @"c:\temp\test\release\test.exe";
                var proc = Process.Start(new ProcessStartInfo(name)
                {
                    UseShellExecute = false,
                    WindowStyle = ProcessWindowStyle.Hidden,
                    RedirectStandardError = true,
                    RedirectStandardOutput = true,
                    CreateNoWindow = true,
                });
                var stdout = proc.StandardOutput.ReadToEndAsync();
                var stderr = proc.StandardError.ReadToEndAsync().Result;
                
                bool ext = proc.WaitForExit(30000);
                File.WriteAllText(@"c:\temp\test.txt", stderr + "\r\n stdout=" + stdout.Result + "\r\n" + proc.ExitCode + "\r\n"+ext);
            }).Start();
        }
    }
    

    }
    @

    Sorry just found out I can't attach file, so I just uploaded the snippets instead.

    Thanks
    gz



  • Never mind, I think I didn't copy the related dlls in.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.