Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Help to get Network Card Mac address

Help to get Network Card Mac address

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 3.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Almero
    wrote on last edited by
    #1

    Hi I have the following code, but it is not working,
    I am only beginner.
    Error I receive is "Internal Error during IMAGE::Pass1

    I 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 network

    Please 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();
    }
    
    jsulmJ 1 Reply Last reply
    0
    • A Almero

      Hi I have the following code, but it is not working,
      I am only beginner.
      Error I receive is "Internal Error during IMAGE::Pass1

      I 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 network

      Please 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();
      }
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Almero When do you get this error message?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Almero
        wrote on last edited by
        #3

        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

        0_1529653370519_ba9efa8c-10ba-467b-8643-a89b78f2bc97-image.png

        jsulmJ 1 Reply Last reply
        0
        • A Almero

          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

          0_1529653370519_ba9efa8c-10ba-467b-8643-a89b78f2bc97-image.png

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Almero Please do a complete rebuild (delete build directory, run qmake and build).

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • A Offline
            A Offline
            Almero
            wrote on last edited by
            #5

            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

            jsulmJ 1 Reply Last reply
            0
            • A Almero

              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

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @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?

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              A 1 Reply Last reply
              3
              • jsulmJ jsulm

                @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?

                A Offline
                A Offline
                Almero
                wrote on last edited by
                #7

                @jsulm

                I have added QT += network as a seperate line in the .pro file and it now works :)
                Thank you so much

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved