我的应用程序出现问题,我试图获取运行它的系统的所有网络配置.最终目标是找到优先级最高的MAC地址.
当我使用QtCreator运行该代码时,该代码可以正常运行,并且当我创建一个包含dll文件和exe文件的文件夹时,该代码也可以正常运行.
但是问题是,当我在其他Windows机器(7和10)上运行该程序时,它可以运行,但是不返回或不显示任何内容.我尝试以管理员身份运行它,但是这两个都不起作用,因此这段代码应该可以在所有Windows平台上运行.
有什么建议吗?
我当前在 Windows 10 上并使用 Qt 5.8 MSVC 2015
exe文件在Windows 10上与这些dll一起运行:
- Qt5Core.dll
- Qt5Network.dll
- msvcp140.dll
- msvcr120.dll
- vcruntime140.dll
对于Windows 7,这些dll也应该存在:
- api-ms-win-core-file-l1-2-0.dll
- api-ms-win-core-file-l2-1-0.dll
- api-ms-win-core-localization-l1-2-0.dll
- api-ms-win-core-processthreads-l1-1-1.dll
- api-ms-win-core-string-l1-1-0.dll
- api-ms-win-core-synch-l1-2-0.dll
- api-ms-win-core-timezone-l1-1-0.dll
- api-ms-win-crt-convert-l1-1-0.dll
- api-ms-win-crt-environment-l1-1-0.dll
- api-ms-win-crt-filesystem-l1-1-0.dll
- api-ms-win-crt-heap-l1-1-0.dll
- api-ms-win-crt-locale-l1-1-0.dll
- api-ms-win-crt-math-l1-1-0.dll
- api-ms-win-crt-multibyte-l1-1-0.dll
- api-ms-win-crt-runtime-l1-1-0.dll
- api-ms-win-crt-stdio-l1-1-0.dll
- api-ms-win-crt-string-l1-1-0.dll
- api-ms-win-crt-time-l1-1-0.dll
- api-ms-win-crt-utility-l1-1-0.dll
下面的链接是exe和dll文件在一起:
按下 Shift +右键单击鼠标,然后在此处单击打开命令窗口
例如,输入windeployqt.exe c:\您的应用程序目录:
windeployqt.exe C:\ Users \ Mofrad \ Downloads \ macfindertest \ macFinderTest \ macAddressTest.exe
现在某些dll将复制到您的应用目录中.
现在再次尝试您的应用程序,您会看到它正在运行.
I'm having a problem with my application, in which I'm trying to get all network configurations of the system that it runs on. The final goal is to find the MAC address with highest priority.
The code runs ok and works when I run it with QtCreator and also runs ok when I create a folder containing the dll files and the exe file.
But the problem is that when I run this program on other windows machines (7 and 10) it runs but does not return or show anything. I tried running it as an Administrator, that didn't work neither and this code should be able to work on all windows platforms.
Any suggestions?
I'm currently on Windows 10 and using Qt 5.8 MSVC 2015
The exe file runs with these dlls on Windows 10:
- Qt5Core.dll
- Qt5Network.dll
- msvcp140.dll
- msvcr120.dll
- vcruntime140.dll
These dlls should be also there for windows 7:
- api-ms-win-core-file-l1-2-0.dll
- api-ms-win-core-file-l2-1-0.dll
- api-ms-win-core-localization-l1-2-0.dll
- api-ms-win-core-processthreads-l1-1-1.dll
- api-ms-win-core-string-l1-1-0.dll
- api-ms-win-core-synch-l1-2-0.dll
- api-ms-win-core-timezone-l1-1-0.dll
- api-ms-win-crt-convert-l1-1-0.dll
- api-ms-win-crt-environment-l1-1-0.dll
- api-ms-win-crt-filesystem-l1-1-0.dll
- api-ms-win-crt-heap-l1-1-0.dll
- api-ms-win-crt-locale-l1-1-0.dll
- api-ms-win-crt-math-l1-1-0.dll
- api-ms-win-crt-multibyte-l1-1-0.dll
- api-ms-win-crt-runtime-l1-1-0.dll
- api-ms-win-crt-stdio-l1-1-0.dll
- api-ms-win-crt-string-l1-1-0.dll
- api-ms-win-crt-time-l1-1-0.dll
- api-ms-win-crt-utility-l1-1-0.dll
Link below is the exe and dll files together:
ufile.io/e9htu
here's my code if needed:
main.cpp
#include <QCoreApplication> #include "macfinder.h" int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); MACFinder macFinder; macFinder.findMAC(); return a.exec(); }macfinder.h
#ifndef MACFINDER_H #define MACFINDER_H #include <QObject> #include <QNetworkConfiguration> #include <QNetworkConfigurationManager> #include <QNetworkInterface> #include <QNetworkSession> #include <QDebug> class MACFinder : public QObject { Q_OBJECT public: explicit MACFinder(QObject *parent = 0); void findMAC(); private: QNetworkConfigurationManager ncm; QString filterMAC(QList<QNetworkConfiguration> configs); signals: void foundMAC(QString MAC); private slots: void configurationsUpdateCompleted(); }; #endif // MACFINDER_Hmacfinder.cpp
#include "macfinder.h" MACFinder::MACFinder(QObject *parent) : QObject(parent) { } QString MACFinder::filterMAC(QList<QNetworkConfiguration> configs) { qDebug() << "MAC and Index: "; QString MAC; int index; QNetworkConfiguration nc; foreach(nc,configs) { QNetworkSession networkSession(nc); QNetworkInterface netInterface = networkSession.interface(); QString debugStr = QString::number(netInterface.index()) + " | " + netInterface.humanReadableName() + " | " + nc.name() + " | " + netInterface.hardwareAddress(); if(netInterface.hardwareAddress().isEmpty()) { qDebug() << "--> No MAC: " << debugStr; continue; } if(netInterface.name().isEmpty()) { qDebug() << "--> NO NAME: " << debugStr; continue; } if(netInterface.index() == 0) { qDebug() << "--> NO INDEX: " << debugStr; continue; } if(netInterface.flags() & QNetworkInterface::IsLoopBack) { qDebug() << "--> loopBack: " << debugStr; continue; } if(netInterface.flags() & (QNetworkInterface::IsRunning | QNetworkInterface::IsUp)) { qDebug() << "*** Accepted: " << debugStr; if(MAC.isEmpty()) { qDebug() << "setting MAC:" << debugStr; MAC = netInterface.hardwareAddress(); index = netInterface.index(); } else { if(netInterface.index() < index) { qDebug() << "setting MAC:" << debugStr; MAC = netInterface.hardwareAddress(); index = netInterface.index(); } else qDebug() << "index is not lower: " << debugStr; } } } return MAC; } void MACFinder::findMAC() { qDebug() << "MACFinder::findMAC | updating all configurations"; connect(&ncm,SIGNAL(updateCompleted()),this,SLOT(configurationsUpdateCompleted())); ncm.updateConfigurations(); } void MACFinder::configurationsUpdateCompleted() { qDebug() << "MACFinder::configurationsUpdateCompleted"; disconnect(&ncm,SIGNAL(updateCompleted()),this,SLOT(configurationsUpdateCompleted())); QNetworkConfiguration nc; QList<QNetworkConfiguration> configs = ncm.allConfigurations(QNetworkConfiguration::Active); qDebug() << "\nAllConfigs: "; foreach (nc,configs) { qDebug() << nc.identifier() << nc.name() << nc.state(); } QString MAC = filterMAC(configs); qDebug() << "\nMAC:" << MAC; if(MAC.isEmpty()) { qDebug("no MAC address found"); } emit foundMAC(MAC); }解决方案
I downloaded your app and analyze it on my computer.
problem is you missing some dlls, your app running without error but not working properly. (qgenericbearer.dll , qnativewifibearer.dll with folder bearer are missing ).
you can use windeploy command to deploy your project.
go to Qt, compiler directory on your OS for example:
C:\Qt\Qt5.7.0\5.7\msvc2013\binpress Shift+right click mouse then click open command window here
type windeployqt.exe c:\Your app directory for example:
windeployqt.exe C:\Users\Mofrad\Downloads\macfindertest\macFinderTest\macAddressTest.exenow some dlls will copy to your app directory.
Now try your app again and you'll see it's working.
更多推荐
程序无法在其他Windows计算机上正常运行
发布评论