首页 文章

程序在其他Windows机器上无法正常工作

提问于
浏览
0

我的应用程序出现问题,我正在尝试获取运行它的系统的所有网络配置 . 最终目标是找到具有最高优先级的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

这些dll应该也适用于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

下面的链接是exe和dll文件在一起:

https://ufile.io/e9htu

如果需要,这是我的代码:

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_H

macfinder.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);
}

1 回答

  • 3

    我下载了您的应用并在我的计算机上进行分析 .

    问题是你错过了一些dll,你的应用运行没有错误但不能正常工作 . ( qgenericbearer.dllqnativewifibearer.dll ,缺少文件夹 bearer ) .

    您可以使用windeploy命令来部署项目 .

    转到操作系统上的Qt编译器目录,例如:

    C:\Qt\Qt5.7.0\5.7\msvc2013\bin
    

    Screenshot1

    Shift+right click mouse 然后 click open command window here

    输入windeployqt.exe c:\您的app目录,例如:

    windeployqt.exe C:\Users\Mofrad\Downloads\macfindertest\macFinderTest\macAddressTest.exe
    

    Screenshot2

    现在一些dll会复制到你的app目录 .

    现在再试一次你的应用程序,你会发现它正在运行 .

    您可以下载应用程序的部署here

相关问题