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. [SOLVED] Can't add custom class!
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Can't add custom class!

Scheduled Pinned Locked Moved General and Desktop
18 Posts 4 Posters 5.7k Views 1 Watching
  • 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.
  • B Offline
    B Offline
    bareil76
    wrote on last edited by
    #1

    Hi all,
    I cannot find why I get this error:

    @hid_pnp.obj:-1: error: LNK2001: unresolved external symbol "public: bool __thiscall CHexManager::LoadHexFile(void)" (?LoadHexFile@CHexManager@@QAE_NXZ)@

    Here is my CHexManager class header
    @#ifndef HEX_H
    #define HEX_H

    #pragma once
    #include "stdio.h"
    #include <QObject>

    typedef struct
    {
    unsigned char RecDataLen;
    unsigned int Address;
    unsigned int MaxAddress;
    unsigned int MinAddress;
    unsigned char RecType;
    unsigned char* Data;
    unsigned char CheckSum;
    unsigned int ExtSegAddress;
    unsigned int ExtLinAddress;
    }T_HEX_RECORD;

    // Hex Manager class
    class CHexManager
    {

    public:
    unsigned int HexTotalLines;
    unsigned int HexCurrLineNo;
    bool LoadHexFile(void);
    --
    //Constructor
    CHexManager()
    {
    HexFilePtr = NULL;
    }
    //Destructor
    ~CHexManager()
    {
    // If hex file is open close it.
    if(HexFilePtr)
    {
    fclose(HexFilePtr);
    }
    }

    private:
    QString HexFilePath;
    FILE *HexFilePtr;

    };

    #endif // HEX_H
    @

    and source

    @
    #include "hex.h"

    #ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = FILE;
    #endif

    // Virtual Flash.
    #define KB (1024)
    #define MB (KB*KB)

    // 5 MB flash
    static unsigned char VirtualFlash[5*MB];

    #define BOOT_SECTOR_BEGIN 0x7FC000

    #define DATA_RECORD 0
    #define END_OF_FILE_RECORD 1
    #define EXT_SEG_ADRS_RECORD 2
    #define EXT_LIN_ADRS_RECORD 4

    /****************************************************************************

    • Loads hex file

    • \param

    • \param

    • \param

    • \return true if hex file loads successfully
      *****************************************************************************/
      bool CHexManager::LoadHexFile(void)
      {
      char HexRec[255];

      HexFilePath = fileDialog.GetPathName();

      // Open file
      HexFilePtr = fopen(HexFilePath, "r");

      if(HexFilePtr == NULL)
      {
      // Failed to open hex file.
      return false;
      }
      else
      {

       HexTotalLines = 0;
       while(!feof(HexFilePtr))
       {
           fgets(HexRec, sizeof(HexRec), HexFilePtr);
           HexTotalLines++;
       }
      

      }

      return true;
      }
      @

    In my MainWindow.h file I have declared in the public section:
    @ CHexManager HexManager; //load Hex manager class@

    and in my MainWindow.c file.. if I try to run @HexManager.LoadHexFile();@

    I get the error.

    What am I doing wrong??

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Buckets
      wrote on last edited by
      #2

      I think I had the issue you are having before.
      I ended up removing my build folder, cleaned the project, then rebuilt it and the linkage error went away.

      ba ba ba
      ba na na na

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dbzhang800
        wrote on last edited by
        #3

        Have you added the hex.cpp file to your project?

        1 Reply Last reply
        0
        • B Offline
          B Offline
          bareil76
          wrote on last edited by
          #4

          Yes.. hex.cpp is in the project tree.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi,

            In the project tree doesn't mean it gets compiled. Do you list in the sources in your pro file ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • B Offline
              B Offline
              bareil76
              wrote on last edited by
              #6

              yes.. it was listed.

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Can you show your pro file ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  bareil76
                  wrote on last edited by
                  #8

                  @#-------------------------------------------------

                  Project created by QtCreator 2012-09-04T13:47:46

                  #-------------------------------------------------
                  QT += gui declarative
                  QT += core gui
                  #DEFINES +=QT_DISABLE_DEPRECATED_BEFORE=0x040800 #0x050100 to disable functions deprecated in Qt 5.1 and earlier
                  greaterThan(QT_MAJOR_VERSION, 4): QT += printsupport

                  TARGET = MyApp
                  TEMPLATE = app

                  SOURCES += main.cpp
                  mainwindow.cpp
                  hid_pnp.cpp
                  qcustomplot.cpp
                  windows/hid.c
                  hex.cpp

                  HEADERS += mainwindow.h
                  hid_pnp.h
                  qcustomplot.h
                  hidapi.h
                  hex.h

                  FORMS += mainwindow.ui

                  #-------------------------------------------------

                  Add the Signal11's hidapi library that was

                  created

                  #-------------------------------------------------
                  macx: LIBS += -L../HIDAPI/mac -lHIDAPI
                  #win32: LIBS += -L../HIDAPI/windows -lHIDAPI
                  unix: !macx: LIBS += -L../HIDAPI/linux -lHIDAPI

                  #-------------------------------------------------

                  Make sure to add the required libraries or

                  frameoworks for the hidapi to work depending on

                  what OS is being used

                  #-------------------------------------------------
                  macx: LIBS += -framework CoreFoundation -framework IOkit
                  win32: LIBS += -lSetupAPI
                  unix: !macx: LIBS += -lusb-1.0

                  #-------------------------------------------------

                  Make sure output directory for object file and

                  executable is in the correct subdirectory

                  #-------------------------------------------------
                  macx {
                  DESTDIR = mac
                  OBJECTS_DIR = mac
                  MOC_DIR = mac
                  UI_DIR = mac
                  RCC_DIR = mac
                  }
                  unix: !macx {
                  DESTDIR = linux
                  OBJECTS_DIR = linux
                  MOC_DIR = linux
                  UI_DIR = linux
                  RCC_DIR = linux
                  }
                  win32 {
                  DESTDIR = windows
                  OBJECTS_DIR = windows
                  MOC_DIR = windows
                  UI_DIR = windows
                  RCC_DIR = windows
                  }

                  @

                  1 Reply Last reply
                  0
                  • B Offline
                    B Offline
                    bareil76
                    wrote on last edited by
                    #9

                    I tried again.. and got the same error.

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Did you delete the build directory and do a full rebuild ?

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • B Offline
                        B Offline
                        bareil76
                        wrote on last edited by
                        #11

                        I just tried and no it doesn't work.

                        It should be so simple!

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          Are all your files in the same folder ?

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          0
                          • B Offline
                            B Offline
                            bareil76
                            wrote on last edited by
                            #13

                            Yes.. they are.

                            Thank you for your help by the way!

                            1 Reply Last reply
                            0
                            • SGaistS Offline
                              SGaistS Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              Are you also calling this function in hid_pnp ?

                              Interested in AI ? www.idiap.ch
                              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                              1 Reply Last reply
                              0
                              • B Offline
                                B Offline
                                bareil76
                                wrote on last edited by
                                #15

                                In hid_pnp.. I setup an instance of the class by using

                                CHexManager HexManager;

                                so calling HexManager.LoadHexFile(); in hid_pnp... will produce the error.

                                1 Reply Last reply
                                0
                                • SGaistS Offline
                                  SGaistS Offline
                                  SGaist
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #16

                                  Then let's go step by step, comment all call to that function and build again, once it does, re-add them one by one.

                                  Interested in AI ? www.idiap.ch
                                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  1 Reply Last reply
                                  0
                                  • B Offline
                                    B Offline
                                    bareil76
                                    wrote on last edited by
                                    #17

                                    THANK YOU!!!!

                                    I got it... I don,t know why I did this. But I had included #include "hid_pnp.h" in my hex.c file.

                                    Going to the strict minimum was a good idea.

                                    1 Reply Last reply
                                    0
                                    • SGaistS Offline
                                      SGaistS Offline
                                      SGaist
                                      Lifetime Qt Champion
                                      wrote on last edited by
                                      #18

                                      You're welcome !

                                      Since you have it working now, don't forget to update the thread title prepending [solved] so other forum users may know a solution has been found :)

                                      Interested in AI ? www.idiap.ch
                                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                      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