[Solved] application name has encountered a problem and needs to close. We are sorry for the inconvenience error when running Qt app on xp
-
__Hello,
I have this piece of code that takes a ppt document and transforms it to a series of images I want to integrate into my Qt application .
@#include "stdafx.h"
#include "msword.h"
#include "ExcelToPic.h"
#include "ppttopic.h"
#include "WordToPic.h"......
void Widget::on_transformButton_clicked()
{
//DO THE BULK OF YOUR TRANSFORMATIONS HEREQString filepath=ui->chooseDocLineEdit->text();
QString outDir=ui->outputLocationLineEdit->text();QFileInfo mFile(filepath);
QString filename=mFile.baseName();QString fileExt=mFile.suffix();
//TRANSFORM THOSE INTO CSTRINGS.
QByteArray destBa1 = filepath.toLocal8Bit();
const char *filepathCString1 = destBa1.data();
CString strFilePath(filepathCString1,destBa1.size());QByteArray destBa4 = outDir.toLocal8Bit();
const char *outDirCString1 = destBa4.data();
CString szOutDir(outDirCString1,destBa4.size());PowerPointToPic(strFilePath, szOutDir,outDir); QMessageBox message; message.setText("Transformtion successful"); message.exec();
}
@
The PowerPointToPic function is implemented as follows:
@void PowerPointToPic(CString szDocName, CString szOutDir,QString outDir)
{CPPTApplication m_powerpointApp;
CPPTPresentations m_powerpointPres;
CPPTPresentation m_powerpointPre;
CPPTSlide slide;
CPPTSlides slides;
m_powerpointPres.ReleaseDispatch();
m_powerpointPre.ReleaseDispatch();try{
CoInitialize(NULL);
if(!m_powerpointApp.CreateDispatch(_T("PowerPoint.Application"), NULL))
{
//AfxMessageBox(_T("创建PowerPoint服务失败!"));
return;
}
}
catch(...)
{
return;
}m_powerpointApp.m_bAutoRelease=true;
m_powerpointApp.put_Visible(long(1));
m_powerpointApp.put_WindowState(long(2));
m_powerpointPres.AttachDispatch(m_powerpointApp.get_Presentations());
m_powerpointPres.Open(szDocName,TRUE, 1, 1);
m_powerpointPre.AttachDispatch(m_powerpointApp.get_ActivePresentation(),TRUE);slides = m_powerpointPre.get_Slides();
int pageCount = slides.get_Count();
for( int i = 1; i <= pageCount; i++ )
{
slide = slides.Range(COleVariant((long)i));
slide.Copy();//_T("c:\test-%d.bmp")
//CString temp; //QString sohokafile="sohokaImage"+QString::number(i); QString sohokafile=outDir+"/sohokaImage"+QString::number(i)+".png"; QByteArray destBa4 = sohokafile.toLocal8Bit(); const char *outDirCString1 = destBa4.data(); CString temp(outDirCString1,destBa4.size()); //slide.Export(_T("c:\\amaImages\\slide1.png"), _T("png"),900,900 ); slide.Export(temp, _T("png"),900,900 );
}
m_powerpointPre.Close();
m_powerpointApp.Quit();
m_powerpointPre.ReleaseDispatch();
m_powerpointPres.ReleaseDispatch();
slides.ReleaseDispatch();
slide.ReleaseDispatch();
m_powerpointApp.ReleaseDispatch();CoUninitialize();
}
@
When I wrap this into a test widget application to see if all works as expected the code turns the ppt document into png images on both win7 and winxp without problems. But when I integrate it within my Qt app ,It only runs on win7 without problems and throws the [application name] has encountered a problem and needs to close. We are sorry for the inconvenience error.
From my "search":http://superuser.com/questions/393950/why-do-applications-need-to-close-or-stop-working-and-what-can-i-do-about-i this is probably due to incompatibilities I can't figure out .I also updated my virtual machine xp system to no avail.The application links to normal Qt 4 dlls and a few other third party libraries.
I would appreciate it if somebody helped with this .Thank you for your time.
-
Hi,
Some things to check:
- Are you using the same flags for both applications ?
- Do you utilize CoInitialize in other places ?
Hope it helps
-
Thanks for the reply ,
I am using the same flags for both applications and CoInitialize is used in some other places in the code(although I disabled them and the problem persists).After some debugging I was able to pinpoint that
@
slide.Export(temp, _T("png"),900,900 );@
is the statement crashing the application .Probably the problem with how I was transforming form Qt strings to CStrings. I used win32 native to get the paths I was interested in and the problem faded away .
-
Did you use the *nix notation until there ? If so you would have to use QDir::toNativeSeparators before passing it to native Windows API