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. use of STL causing LINK2019 linker error
QtWS25 Last Chance

use of STL causing LINK2019 linker error

Scheduled Pinned Locked Moved Unsolved General and Desktop
link errorstl
4 Posts 3 Posters 736 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.
  • J Offline
    J Offline
    jonah765
    wrote on 21 Aug 2020, 16:28 last edited by jonah765
    #1

    Hello, So I have the following function:

    void StartWindow::newPOTWButtonClicked()
    {
        std::cout << "creating new POTW" << std::endl;
    
        //generate new window
        POTWSetupWindow setupWindow;
    
        //generate questions
        QuestionBox* week = new QuestionBox("What week is it?");
    
        //add question elements and link to correct slot
        std::function<void(void)>func(std::bind(&POTWSetupWindow::weekFilled, &setupWindow));
        week->addDropDownItem(1,100, func);
        
        //push questions to POTW setup window
        setupWindow.addQuestion(week);
    
        emit setNewMainWindow(setupWindow);
    }
    
    

    However, this throws the following linker error:

    startwindow.obj:-1: error: LNK2019: unresolved external symbol "public: void __cdecl POTWSetupWindow::weekFilled(void)" (?weekFilled@POTWSetupWindow@@QEAAXXZ) referenced in function "public: void __cdecl StartWindow::newPOTWButtonClicked(void)" (?newPOTWButtonClicked@StartWindow@@QEAAXXZ)
    

    Now, the error goes away If I run the code without the use of std::function and std::bind , so it appears to me that they are causing the problems. My .pro file looks as follows, which likely needs to be changed to solve my problem:

    QT       += core gui
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    CONFIG += c++14
    
    DEFINES += QT_DEPRECATED_WARNINGS
    
    SOURCES += \
        button.cpp \
        fancyslider.cpp \
        main.cpp \
        mainwindow.cpp \
        potwsetupwindow.cpp \
        startwindow.cpp \
        questionbox.cpp \
    
    HEADERS += \
        button.h \
        fancyslider.h \
        mainwindow.h \
        potwsetupwindow.h \
        startwindow.h \
        questionbox.h \
    
    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target
    

    Also, my project is using Desktop Qt 5.14.2 MSCV2017 64 Bit

    1 Reply Last reply
    0
    • F Offline
      F Offline
      fcarney
      wrote on 21 Aug 2020, 17:04 last edited by fcarney
      #2

      @jonah765 said in use of STL causing LINK2019 linker error:

      std::function<void(void)>func(std::bind(&POTWSetupWindow::weekFilled, &setupWindow));

      Why are you using std::function and std::bind? std::bind should return a function object.

      You are also storing a pointer to an object that will be destroyed at the end of this function:

      POTWSetupWindow setupWindow;
      

      Is your setupWindow QObject based? Then you can create it with new and have the parent object in the constructor. This will handle destruction when the parent window/object gets deleted.

      Edit:
      How is weekFilled defined?

      C++ is a perfectly valid school of magic.

      J 1 Reply Last reply 21 Aug 2020, 18:57
      2
      • F fcarney
        21 Aug 2020, 17:04

        @jonah765 said in use of STL causing LINK2019 linker error:

        std::function<void(void)>func(std::bind(&POTWSetupWindow::weekFilled, &setupWindow));

        Why are you using std::function and std::bind? std::bind should return a function object.

        You are also storing a pointer to an object that will be destroyed at the end of this function:

        POTWSetupWindow setupWindow;
        

        Is your setupWindow QObject based? Then you can create it with new and have the parent object in the constructor. This will handle destruction when the parent window/object gets deleted.

        Edit:
        How is weekFilled defined?

        J Offline
        J Offline
        jonah765
        wrote on 21 Aug 2020, 18:57 last edited by
        #3

        Thanks a lot for your response, I appreciate the effort, but the error was in the end something trivial.

        A 1 Reply Last reply 22 Aug 2020, 04:32
        0
        • J jonah765
          21 Aug 2020, 18:57

          Thanks a lot for your response, I appreciate the effort, but the error was in the end something trivial.

          A Offline
          A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on 22 Aug 2020, 04:32 last edited by
          #4

          @jonah765 said in use of STL causing LINK2019 linker error:

          Thanks a lot for your response, I appreciate the effort, but the error was in the end something trivial.

          ... and would you like to share the trivial solution? It might help later readers.

          Thanks

          Qt has to stay free or it will die.

          1 Reply Last reply
          1

          1/4

          21 Aug 2020, 16:28

          • Login

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