Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Application exception when starting from a service
Forum Updated to NodeBB v4.3 + New Features

Application exception when starting from a service

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 856 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gzhangx
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • G Offline
      G Offline
      gzhangx
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved