本文整理汇总了C++中QAxObject::setControl方法的典型用法代码示例。如果您正苦于以下问题:C++ QAxObject::setControl方法的具体用法?C++ QAxObject::setControl怎么用?C++ QAxObject::setControl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QAxObject
的用法示例。
在下文中一共展示了QAxObject::setControl方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CoInitialize
unsigned int WINAPI TextSpeech::ThreadTextToSpeech(void *arg)
{
CoInitialize(NULL);
QAxObject voiceObj;
bool bSuccess = voiceObj.setControl("96749377-3391-11D2-9EE3-00C04F797396");
if(bSuccess)
{
voiceObj.dynamicCall("SetRate(int)",-3).toInt();
voiceObj.dynamicCall("Speak(QString,SpeechVoiceSpeakFlags)",((TextSpeech *)arg)->m_strToSpeak,0).toInt();
}
CoUninitialize();
((TextSpeech *)arg)->SpeakThreadComplete();
return 0;
}
示例2: export_excel_clicked
void SongsQueryWideget::export_excel_clicked()
{
///建立临时表映射
///
setCursor(Qt::WaitCursor);
QSqlQueryModel *sqlquery = new QSqlQueryModel(this);
QSqlQuery _query;
MediaPagingQuery argu;
getQueryCondition(argu);
if(!_sql->queryMedia_All(argu, _query))
return;
sqlquery->setQuery(_query);
int rows = sqlquery->rowCount();
int columns = sqlquery->columnCount();
setCursor(Qt::ArrowCursor);
QString desktopPath = QProcessEnvironment::systemEnvironment().value("USERPROFILE")+"\\Desktop";
QString fileName = QFileDialog::getSaveFileName(tableView_songsQuery, "保存",
//QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation),
desktopPath,
"Excel 文件(*.xls *.xlsx)");
QProgressDialog *progress = new QProgressDialog(this);
progress->setLabelText("正在导出表格数据……");
progress->setRange(0, rows);
progress->setModal(true);
progress->setCancelButtonText("取消");
// progress->setMinimumSize(300, 50);
progress->setMinimumWidth(400);
progress->setAutoClose(true);
if (fileName!="")
{
QAxObject *excel = new QAxObject;
if (excel->setControl("Excel.Application")) //连接Excel控件
{
excel->dynamicCall("SetVisible (bool Visible)","false");//不显示窗体
excel->setProperty("DisplayAlerts", false);//不显示任何警告信息。如果为true那么在关闭是会出现类似“文件已修改,是否保存”的提示
QAxObject *workbooks = excel->querySubObject("WorkBooks");//获取工作簿集合
workbooks->dynamicCall("Add");//新建一个工作簿
QAxObject *workbook = excel->querySubObject("ActiveWorkBook");//获取当前工作簿
QAxObject *worksheet = workbook->querySubObject("Worksheets(int)", 1);
// //数据区
for(int i=0; i<rows; i++)
{
for (int j=0;j<columns; j++)
{
QModelIndex index = sqlquery->index(i, j);
QString text = index.data().toString();
// table->item(i,j)?table->item(i,j)->text():""
worksheet->querySubObject("Cells(int,int)", i+1, j+1)->dynamicCall("SetValue(const QString&)", text);
}
QString label_text = QString("正在导出%1行……").arg(i+1);
progress->setLabelText(label_text);
progress->setValue(i+1);
if(progress->wasCanceled())
{
break;
}
}
workbook->dynamicCall("SaveAs(const QString&)",QDir::toNativeSeparators(fileName));//保存至fileName
workbook->dynamicCall("Close()");//关闭工作簿
//关闭excel
excel->dynamicCall("Quit (void)");
delete excel;
excel=NULL;
QMessageBox box(QMessageBox::Question, "完成", "文件已经导出,是否现在打开?");
box.setStandardButtons(QMessageBox::Yes|QMessageBox::No);
box.setButtonText(QMessageBox::Yes, "确定(&Q)");
box.setButtonText(QMessageBox::No, "取消(&C)");
if(box.exec() == QMessageBox::Yes)
// if (QMessageBox::question(NULL,"完成","文件已经导出,是否现在打开?",QMessageBox::Yes|QMessageBox::No)==QMessageBox::Yes)
{
QString local_path = QString("file:///") + fileName;
QDesktopServices::openUrl(QUrl(local_path, QUrl::TolerantMode)); //QDir::toNativeSeparators(fileName)));
}
}
else
{
QMessageBox::warning(NULL,"错误","未能创建 Excel 对象,请安装 Microsoft Excel。",QMessageBox::Apply);
}
}
// progress->close();
}