Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Learning
  3. Qt in Education
  4. Qt for begginers :10 subclassing Qt widget .
Forum Updated to NodeBB v4.3 + New Features

Qt for begginers :10 subclassing Qt widget .

Scheduled Pinned Locked Moved Qt in Education
10 Posts 2 Posters 4.9k Views 2 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.
  • X Offline
    X Offline
    XDen
    wrote on last edited by
    #1

    Hello , I have a problem . It can not link .
    main.obj:-1: ошибка: LNK2019: unresolved external symbol "public: __cdecl Window::Window(class QWidget *)" (??0Window@@QEAA@PEAVQWidget@@@Z) referenced in function main
    Can some one help me ?

    1 Reply Last reply
    1
    • Chris KawaC Online
      Chris KawaC Online
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi, welcome to devnet.

      Apparently you have not defined a constructor for your class Window.

      1 Reply Last reply
      0
      • X Offline
        X Offline
        XDen
        wrote on last edited by
        #3

        I copy and insert text in my project , I cant understand why this dont work =\

        #include <QApplication>
        #include "window.h"

        int main(int argc, char **argv)
        {
        QApplication app (argc, argv);

        Window window;
        window.show();

        return app.exec();
        }

        1 Reply Last reply
        0
        • Chris KawaC Online
          Chris KawaC Online
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by Chris Kawa
          #4

          As I said - apparently you haven't defined a constructor for your Window class. Can you show Window.h and Window .cpp files?

          1 Reply Last reply
          0
          • X Offline
            X Offline
            XDen
            wrote on last edited by
            #5

            //window.h
            #ifndef WINDOW_H
            #define WINDOW_H

            #include <QWidget>

            class QPushButton;
            class Window : public QWidget
            {
            public:
            explicit Window(QWidget *parent = 0);
            private:
            QPushButton *m_button;
            };

            #endif // WINDOW_H

            //window.cpp
            #include "window.h"

            #include <QPushButton>

            Window::Window(QWidget *parent) :
            QWidget(parent)
            {
            // Set size of the window
            setFixedSize(100, 50);

            // Create and position the button
            m_button = new QPushButton("Hello World", this);
            m_button->setGeometry(10, 10, 80, 30);
            }

            1 Reply Last reply
            0
            • Chris KawaC Online
              Chris KawaC Online
              Chris Kawa
              Lifetime Qt Champion
              wrote on last edited by Chris Kawa
              #6

              Ok, these seem fine. So if the linker can't see the constructor then it means the compiler didn't compile the Window.cpp file. Can you confirm you added it in your project file (.pro) and re-run qmake?

              Btw. When pasting code in the forum surround it with ``` (three backticks). This will format it for better reading.

              1 Reply Last reply
              0
              • X Offline
                X Offline
                XDen
                wrote on last edited by
                #7

                I have : main.cpp , Qt1.pro , window.cpp and window.h files . I dont know re-run qmake , Im begginer .

                1 Reply Last reply
                0
                • Chris KawaC Online
                  Chris KawaC Online
                  Chris Kawa
                  Lifetime Qt Champion
                  wrote on last edited by Chris Kawa
                  #8

                  The project file is Qt1.pro. This is where you define which files are part of your project. There should be a section in it looking like this:

                  HEADERS += window.h
                  
                  SOURCES += main.cpp \
                             window.cpp
                  

                  The error you pasted can mean you're missing the window.cpp file from the SOURCES section.
                  After you add it there (if it's missing) re-run qmake (it's a tool that reads this .pro file and generates makefiles for your compiler). You do that by clicking "run qmake" in the "Build" menu in Qt Creator.

                  1 Reply Last reply
                  0
                  • X Offline
                    X Offline
                    XDen
                    wrote on last edited by
                    #9

                    Thank you , "Run Qmake" work =) I use only green triangle >.< Now all work .

                    1 Reply Last reply
                    0
                    • Chris KawaC Online
                      Chris KawaC Online
                      Chris Kawa
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Great. You only need to run qmake when you change the contents of the project file.

                      1 Reply Last reply
                      3

                      • Login

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