Help to get Network Card Mac address
-
Hi I have the following code, but it is not working,
I am only beginner.
Error I receive is "Internal Error during IMAGE::Pass1I wish to get a string that I can pass into a label or somewhere.
I assume my problem is that I copied the code but it needs to be declared somewhere
and also that my QString getMacAddress() function I am using incorrect.I have edited the .pro file with the first line to look like this:
QT += core gui networkPlease help me
#include "mainwindow.h" #include "ui_mainwindow.h" #include "QString" #include "QtNetwork/QNetworkInterface" #include "QtNetwork/QtNetwork" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); } MainWindow::~MainWindow() { delete ui; } QString getMacAddress() { foreach(QNetworkInterface netInterface, QNetworkInterface::allInterfaces()) { // Return only the first non-loopback MAC Address if (!(netInterface.flags() & QNetworkInterface::IsLoopBack)) return netInterface.hardwareAddress(); } return QString(); }
-
@Almero It doesn't matter where it is for your error message. The problem is: your app is not linked against the Qt network module, so linker cannot find the symbols. Are you sure you have QT += network in your pro file? And did you delete the build directory before running qmake as I suggested?