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" );
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++ )
{
{
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();
}
}
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();
}
}
To copy to clipboard, switch view to plain text mode
Maybe someone has some more experience with ActiveQt and an idea how can I solve this serious problem.
Bookmarks