C++ 程序在其他windows计算机上无法正常工作
我的应用程序有问题,我试图获取它运行的系统的所有网络配置。最终目标是找到具有最高优先级的MAC地址 当我使用QtCreator运行代码时,代码运行正常,工作正常;当我创建包含dll文件和exe文件的文件夹时,代码运行正常 但问题是,当我在其他windows机器(7和10)上运行此程序时,它运行但不返回或显示任何内容。我试着以管理员的身份运行它,但这也不起作用,而且这段代码应该可以在所有windows平台上运行 有什么建议吗 我目前使用的是Windows10,使用的是Qt5.8MSVC2015 exe文件在Windows 10上与以下DLL一起运行:C++ 程序在其他windows计算机上无法正常工作,c++,qt,dll,qt5,qt-creator,C++,Qt,Dll,Qt5,Qt Creator,我的应用程序有问题,我试图获取它运行的系统的所有网络配置。最终目标是找到具有最高优先级的MAC地址 当我使用QtCreator运行代码时,代码运行正常,工作正常;当我创建包含dll文件和exe文件的文件夹时,代码运行正常 但问题是,当我在其他windows机器(7和10)上运行此程序时,它运行但不返回或显示任何内容。我试着以管理员的身份运行它,但这也不起作用,而且这段代码应该可以在所有windows平台上运行 有什么建议吗 我目前使用的是Windows10,使用的是Qt5.8MSVC2015 e
- Qt5Core.dll
- Qt5Network.dll
- msvcp140.dll
- msvcr120.dll
- vcruntime140.dll
- api-ms-win-core-file-l1-2-0.dll
- api-ms-win-core-file-l2-1-0.dll
- api-ms-win-core-LOCATIONAL-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-LOCE-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
#include <QCoreApplication>
#include "macfinder.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
MACFinder macFinder;
macFinder.findMAC();
return a.exec();
}
#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);
}
#包括
#包括“macfinder.h”
int main(int argc,char*argv[])
{
qcorea应用程序(argc、argv);
MACFinder MACFinder;
macFinder.findMAC();
返回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_H
\ifndef MACFINDER\u H
#定义MACFINDER\u H
#包括
#包括
#包括
#包括
#包括
#包括
MACFinder类:公共QObject
{
Q_对象
公众:
显式MACFinder(QObject*parent=0);
void findMAC();
私人:
QNetworkConfigurationManager ncm;
QString filterMAC(QList配置);
信号:
void foundMAC(QString MAC);
专用插槽:
void configurationsUpdateCompleted();
};
#endif//MACFINDER\u H
macfinder.cpp
#include <QCoreApplication>
#include "macfinder.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
MACFinder macFinder;
macFinder.findMAC();
return a.exec();
}
#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);
}
#包括“macfinder.h”
MACFinder::MACFinder(QObject*父对象):QObject(父对象)
{
}
QString MACFinder::filterMAC(QList配置)
{
qDebug()我下载了你的应用程序,并在我的电脑上对其进行了分析
问题是您缺少一些dll,您的应用程序运行时没有错误,但工作不正常。(qgenericbearrer.dll
,qnativewifibearer.dll
缺少文件夹bearer
)
可以使用windeploy命令部署项目
转到操作系统上的Qt编译器目录,例如:
C:\Qt\Qt5.7.0\5.7\msvc2013\bin
windeployqt.exe C:\Users\Mofrad\Downloads\macfindertest\macFinderTest\macAddressTest.exe
按Shift键并右键单击鼠标
,然后单击此处的打开命令窗口
键入windeployqt.exe c:\Your app directory,例如:
C:\Qt\Qt5.7.0\5.7\msvc2013\bin
windeployqt.exe C:\Users\Mofrad\Downloads\macfindertest\macFinderTest\macAddressTest.exe
现在一些DLL将复制到您的应用程序目录
现在再次尝试您的应用程序,您将看到它正在工作。我下载了您的应用程序,并在我的计算机上对其进行了分析 问题是您缺少一些dll,您的应用程序运行时没有错误,但工作不正常。(
qgenericbearrer.dll
,qnativewifibearer.dll
缺少文件夹bearer
)
可以使用windeploy命令部署项目
转到操作系统上的Qt编译器目录,例如:
C:\Qt\Qt5.7.0\5.7\msvc2013\bin
windeployqt.exe C:\Users\Mofrad\Downloads\macfindertest\macFinderTest\macAddressTest.exe
按Shift键并右键单击鼠标,然后单击此处的打开命令窗口
键入windeployqt.exe c:\Your app directory,例如:
C:\Qt\Qt5.7.0\5.7\msvc2013\bin
windeployqt.exe C:\Users\Mofrad\Downloads\macfindertest\macFinderTest\macAddressTest.exe
现在一些DLL将复制到您的应用程序目录
现在重试你的应用程序,你会看到它正在工作。可能其他windows防火墙阻止了你的应用程序。将其添加到防火墙列表,我不会发送或接收任何包扫描你的项目(exe文件+dll)并将其上载到下载位置。调试它。添加一组日志,以便您可以查看执行路径、函数调用的返回值等。我已上载文件链接是:可能其他windows防火墙阻止了您的应用。将其添加到防火墙列表中,我不会发送或接收任何包扫描您的项目(exe文件+dll)并将其上载到下载位置。调试它。添加一组日志记录,以便您可以查看执行路径、函数调用的返回值等。我已上载文件链接为: