PDA

View Full Version : Problems with QAxObject and accessing Office Word when App running as QtService



Ralf83
1st May 2010, 12:41
Hello,

I am devoloping an Application which should run as Service on a Windows machine. The App receives Word Documents over Network and opens then over the ActiveQt and print them out.

The whole process works fine when i ran the app in debug mode ( the service with the -e option ), but when I start the service in normal operation, the word document couldn't be open. Because there is no exception or any other error message, I have no Idea where the problem might be.

When the app in serice mode tries to open the document the method querySubObject returns an NULL-Pointer.

Here is the Code of the Function which does the printing process( it runs in an own thread ):




void Printjob::SlotPrintDocs()
{
qDebug() << "Current Thread: " << currentThreadId();
emit SignalAddLogEntry( QString( "Drucke: Job=%1, User=%2, Drucker=%3" ).arg( m_jobId ).arg( m_user ).arg( m_printer ) );


if( CoInitializeEx( 0, COINIT_MULTITHREADED ) != S_OK )
{
emit SignalAddLogEntry( "Konnte COM-Objekt im Printjob Thread nicht initialisieren" );
}

emit SignalAddLogEntry( "Starte Word" );
QAxObject* pWord = new QAxObject( "Word.Application" );
pWord->setProperty( "Visible", true );
QAxObject* pDocuments = pWord->querySubObject( "Documents" );
QString lastPrinter = pWord->property( "ActivePrinter" ).toString();

connect( pWord, SIGNAL( exception ( int, const QString&, const QString&, const QString& ) ), this, SLOT( SlotComException( int, const QString&, const QString&, const QString& ) ) );
connect( pDocuments, SIGNAL( exception ( int, const QString&, const QString&, const QString& ) ), this, SLOT( SlotComException( int, const QString&, const QString&, const QString& ) ) );


if( ! pWord || ! pDocuments )
{
emit SignalAddLogEntry( "Konnte Word nicht öffnen" );
}

if( ! pWord->setProperty( "ActivePrinter", m_printer ) )
{
emit SignalAddLogEntry( "Konnte Drucker nicht wechseln" );
}
qDebug() << pWord->property( "ActivePrinter" ).toString();

for( int i = 0; i < m_docs.size(); i++ )
{
if( ! QFileInfo( m_docs.at( i ) ).exists() )
{
emit SignalAddLogEntry( "Konnte folgenden Dokument nicht finden: " + m_docs.at( i ) );
continue;
}
if( ! QFileInfo( m_docs.at( i ) ).isReadable() )
{
emit SignalAddLogEntry( "Konnte folgenden Dokument nicht lesen: " + m_docs.at( i ) );
continue;
}

if( m_abortPrint )
{
break;
}

emit SignalAddLogEntry( "Öffne Dokument: " + m_docs.at( i ) );

QVariantList params;
params << m_docs.at( i ) << true << false << false << "" << "" << false << false << "" << "" << 0 << false << true << 0 << true << false;
QAxObject* pDoc = pDocuments->querySubObject( "OpenNoRepairDialog (QVariant&, QVariant&, QVariant&, QVariant&, QVariant&, QVariant&, QVariant&, QVariant&, QVariant&, QVariant&, QVariant&, QVariant&, QVariant&, QVariant&, QVariant&, QVariant&)", params );
if( ! pDoc )
{
emit SignalAddLogEntry( "Konnte Dokument nicht öffnen: " + m_docs.at( i ) );
continue;
}
connect( pDoc, SIGNAL( exception ( int, const QString&, const QString&, const QString& ) ), this, SLOT( SlotComException( int, const QString&, const QString&, const QString& ) ) );
emit SignalAddLogEntry( "Drucke Dokument: " + m_docs.at( i ) );
pDoc->dynamicCall( "PrintOut(boolean)", false );
emit SignalAddLogEntry( "Schliesse Dokument: " + m_docs.at( i ) );
pDoc->dynamicCall( "Close(boolean)", false );
delete pDoc;

m_printedDocs.append( m_docs.at( i ) );
emit SignalSendPrintedDoc( m_docs.at( i ) );
}

pWord->setProperty( "ActivePrinter", lastPrinter );
qDebug() << pWord->property( "ActivePrinter" ).toString();

emit SignalAddLogEntry( "Beende Word" );
pWord->dynamicCall( "Quit()" );

delete pDocuments;
delete pWord;
emit SignalFinishedPrinting();

if( m_abortPrint || m_docs.size() == m_printedDocs.size() )
{
m_pParent->deleteLater();
}
}

Maybe someone has some more experience with ActiveQt and an idea how can I solve this serious problem.


Ralf