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(); }
-
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(); }
-
I had a weird error now, so I deleted the project and started a new one. I left the .pro file exactly as is.
I now get this error.Error is on windows machine
-
I have run qmake, rebuild all etc but the error is still the same.
Is "QString getMacAddress()" function even at the correct place?
does it not need to be directly after "ui->setupUi(this);" for example?using QT5.9.2 MSVC 2015
@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?
-
@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?