Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void MainWindow::on_pushButton_3_clicked()
- {
- QAxObject *objIWbemLocator = new QAxObject("WbemScripting.SWbemLocator");
- if (!objIWbemLocator) {
- qDebug("WbemScripting.SWbemLocator not created");
- }
- QAxObject *objWMIService = objIWbemLocator->querySubObject(
- "ConnectServer(QString&,QString&)", //objWMIService - объявляем как переменную член класса, память выделяем в конструкторе
- QString("."), QString("root\\cimv2")); // пространство имен. Если и домен и рабочая группа, можно прикрутить аутентификацию
- if (!objWMIService) {
- qDebug("WMIService not created");
- delete objIWbemLocator;
- }
- QString query = QString( "SELECT * FROM Win32_PhysicalMemory"); // выбранный класс
- QAxObject *objInterList = objWMIService->querySubObject(
- "ExecQuery(QString&))", query);
- if (!objInterList) {
- qDebug("Answer from ExecQuery is null");
- delete objIWbemLocator;
- }
- if (objInterList->dynamicCall("Count").toInt() == 0) {
- qDebug("Count is 0");
- delete objIWbemLocator;
- }
- // И теперь самое интересное
- QAxObject *enum1 = objInterList->querySubObject("_NewEnum");
- if (!enum1) {
- qDebug("Query _NewEnum failed");
- delete objIWbemLocator;
- }
- IEnumVARIANT* enumInterface = 0;
- enum1->queryInterface(IID_IEnumVARIANT, (void**)&enumInterface);
- if (!enumInterface) {
- qDebug("Query interface failed");
- delete objIWbemLocator;
- }
- enumInterface->Release();
- QAxObject *item = 0;
- for (int i = 0; i < objInterList->dynamicCall("Count").toInt(); i++) {
- VARIANT *theItem = (VARIANT*)malloc(sizeof(VARIANT));
- if (enumInterface->Next(1,theItem,NULL) == S_FALSE) {
- qDebug("enum next failed");
- delete theItem;
- delete objIWbemLocator;
- }
- item = new QAxObject((IUnknown*)theItem->punkVal);
- if (!item) {
- qDebug("getting result item failed");
- delete theItem;
- delete objIWbemLocator;
- }
- delete theItem;
- int t;
- // std::stringstream sstr;
- // ui->textEdit->setText(item->dynamicCall("Capacity").toString());
- // std::string st;
- // st = item->dynamicCall("Capacity").toString().toStdString();
- QString st;
- st=item->dynamicCall("Capacity").toString();
- bool k;
- int ska =atoi(st.toStdString().c_str());
- // qDebug()<<st.c_str();
- // sstr<<st.c_str();
- // sstr>>t;
- // t= std::stoi(st.c_str(), 0,10);
- // qDebug()<<"число "<<t;
- ui->textEdit->setText(QString::number(ska));
- }
- delete objIWbemLocator;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement