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. unresolved external symbol "public: static struct QMetaObject const staticMetaObject"
QtWS25 Last Chance

unresolved external symbol "public: static struct QMetaObject const staticMetaObject"

Scheduled Pinned Locked Moved Solved General and Desktop
qt6qmetaobjectmsvc2022
26 Posts 4 Posters 4.1k 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
    a_coder
    wrote on last edited by a_coder
    #1

    i have some error in my code when i build it in visual studio

    1>mainw.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const Mainw::staticMetaObject" (?staticMetaObject@Mainw@@2UQMetaObject@@B)
    1>main.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const Workspace::staticMetaObject" (?staticMetaObject@Workspace@@2UQMetaObject@@B)
    1>mainw.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const Workspace::staticMetaObject" (?staticMetaObject@Workspace@@2UQMetaObject@@B)
    1>mainw.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __cdecl Mainw::metaObject(void)const " (?metaObject@Mainw@@UEBAPEBUQMetaObject@@XZ)
    1>mainw.obj : error LNK2001: unresolved external symbol "public: virtual void * __cdecl Mainw::qt_metacast(char const *)" (?qt_metacast@Mainw@@UEAAPEAXPEBD@Z)
    1>mainw.obj : error LNK2001: unresolved external symbol "public: virtual int __cdecl Mainw::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@Mainw@@UEAAHW4Call@QMetaObject@@HPEAPEAX@Z)
    1>mainw.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __cdecl Workspace::metaObject(void)const " (?metaObject@Workspace@@UEBAPEBUQMetaObject@@XZ)
    1>mainw.obj : error LNK2001: unresolved external symbol "public: virtual void * __cdecl Workspace::qt_metacast(char const *)" (?qt_metacast@Workspace@@UEAAPEAXPEBD@Z)
    1>mainw.obj : error LNK2001: unresolved external symbol "public: virtual int __cdecl Workspace::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@Workspace@@UEAAHW4Call@QMetaObject@@HPEAPEAX@Z)
    

    this is my code
    mainw.h

    #include <ui_mainw.h>
    #include <ui_forcus.h>
    #include <qmainwindow.h>
    #include "control.h"
    #include "qprocess.h"
    
    class Timer;
    class control;
    
    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    class Mainw : public QMainWindow {
    	Q_OBJECT
    public:
    	void start();
    	Mainw(Timer* time, QWidget* parent = nullptr);
    	~Mainw();
    signals:
    	void change_gui() {}
    private:
    	Ui::Main* ui;
    	Timer* timer;
    private slots:
    	void updatetime(long long time);
    	void toworkspace() {
    		ui->pushButton->setDisabled(true);
    		emit change_gui();
    		this->close();
    	}
    };
    
    
    
    class Workspace : public QWidget {
    	Q_OBJECT
    public:
    	Workspace(Timer* time, QWidget* parent = nullptr);
    	~Workspace();
    	void start();
    signals:
    	void change_gui() {}
    private:
    	//store all processes the ui run in a vector
    	std::vector<QProcess*> processes;
    	Ui::workspace* ui;
    	Timer* timer;
    private slots:
    	void updatetime(long long time);
    	void goback();
    };
    #endif // !MAINWINDOW_H
    

    mainw.cpp

    #include <qtimer.h>
    #include <qdatetime.h>
    #include <qmessagebox.h>
    #include "control.h"
    #include "mainw.h"
    Mainw::Mainw(Timer* time, QWidget* parent)
        :QMainWindow(parent)
        ,timer(time)
        ,ui(new Ui::Main)
    {
    	ui->setupUi(this);
    }
    
    Mainw::~Mainw() {
    	delete ui;
    }
    void Mainw::updatetime(long long time) {
        QLabel* text = ui->label;
        int hour = time / 3600;
        int minutes = time / 60;
        int second = time % 60;
        text->setText(QString("%1:%2:%3")
            .arg(hour, 2, 10, QChar('0'))
            .arg(minutes, 2, 10, QChar('0'))
            .arg(second, 2, 10, QChar('0')));
    }
    void Mainw::start() {
    
        QLabel* text = ui->label;
    	text->setText("__:__:__");
        text->setAlignment(Qt::AlignCenter);
    
        connect(timer, &Timer::requestupdated, this, &Mainw::updatetime);
    
    	connect(ui->pushButton, &QPushButton::clicked, this, &Mainw::toworkspace);
    	this->raise();
    	this->showFullScreen();
        this->show();
    }
    
    //setup Workspace
    Workspace::Workspace(Timer* time, QWidget* parent)
    	:QWidget(parent)
    	,ui(new Ui::workspace)
    	,timer(time)
    {
    	ui->setupUi(this);
    	connect(timer, &Timer::requestupdated, this, &Workspace::updatetime);
    }
    
    Workspace::~Workspace() {
    	delete ui;
    }
    
    void Workspace::start() {
    
    	//set text for timer
    
    	QLabel* text = ui->time;
    	QLabel* text2 = ui->count;
    	text->setText("__:__:__");
    	text2->setText("__:__:__");
    
    	//connect button
    
    	connect(timer, &Timer::requestupdated, this, &Workspace::updatetime);
    	QPushButton* button = ui->back;
    	connect(button, &QPushButton::clicked, this, &Workspace::goback);
    
    	//show workspace
    
    	this->raise();
    	this->showFullScreen();
    	this->show();
    }
    
    void Workspace::updatetime(long long time) {
    	//update time remain to label name "timer"
    	QLabel* text2 = ui->count;
    	int hour2 = time / 3600;
    	int minutes2 = time / 60;
    	int second2 = time % 60;
    	text2->setText(QString("%1:%2:%3")
    		.arg(hour2, 2, 10, QChar('0'))
    		.arg(minutes2, 2, 10, QChar('0'))
    		.arg(second2, 2, 10, QChar('0')));
        //update system time to label name "time"
        QLabel* text = ui->time;
    	QDateTime now = QDateTime::currentDateTime();
        text->setText(QString(now.toString("HH:mm:ss")));
    }
    
    void Workspace::goback() {
    	//show warming message if there is some proess running
    	if (processes.size() > 0) {
    		QMessageBox msgBox;
    		msgBox.setText("There is some proess running,if you exit the process will be close \ndo you want to exit?");
    		msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
    		msgBox.setDefaultButton(QMessageBox::No);
    		int ret = msgBox.exec();
    		if (ret == QMessageBox::Yes) {
    			//kill all process in vector
    			for (int i = 0; i < processes.size(); i++) {
    				processes[i]->kill();
    				delete processes[i];
    			}
    			emit change_gui();
    			this->close();
    		}
    	}
    	else {
    		emit change_gui();
    		this->close();
    	}
    }
    
    JonBJ 1 Reply Last reply
    0
    • A a_coder

      @jsulm i detached it before and these are my files
      mainw.h

      #ifndef MAINW_H
      #define MAINW_H
      
      #include <qmainwindow.h>
      #include "ui_mainw.h"
      #include "control.h"
      
      class Timer;
      class control;
      
      class Mainw : public QMainWindow {
      	Q_OBJECT
      public:
      	void start();
      	Mainw(Timer* time, QWidget* parent = nullptr);
      	~Mainw();
      signals:
      	void change_gui();
      private:
      	Ui::Main* ui;
      	Timer* timer;
      private slots:
      	void updatetime();
      	void toworkspace() {
      		ui->pushButton->setDisabled(true);
      		emit change_gui();
      		this->close();
      	}
      };
      #endif // !MAINW_H
      

      workspace.h

      #ifndef WORKSPACE_H
      #define WORKSPACE_H
      
      #include <qprocess.h>
      #include <qmainwindow.h>
      #include "ui_workspace.h"
      #include "control.h"
      
      class Timer;
      
      class Workspace : public QWidget {
      	Q_OBJECT
      public:
      	Workspace(Timer* time, QWidget* parent = nullptr);
      	~Workspace();
      	void start();
      signals:
      	void change_gui();
      private:
      	//store all processes the ui run in a vector
      	std::vector<QProcess*> processes;
      	Ui::workspace* ui;
      	Timer* timer;
      private slots:
      	void updatetime();
      	void goback();
      };
      
      #endif // WORKSPACE_H
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #25

      @a_coder said in unresolved external symbol "public: static struct QMetaObject const staticMetaObject":

      #include "control.h"

      class Timer;
      class control;

      You have a circular dependency: mainw.h includes control.h and control.h includes mainw.h. This is not going to work. Since you only use Timer* in mainw.h and already have a forward declaration for it, the control.h include is not needed, remove it.

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

      A 1 Reply Last reply
      0
      • A a_coder

        i have some error in my code when i build it in visual studio

        1>mainw.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const Mainw::staticMetaObject" (?staticMetaObject@Mainw@@2UQMetaObject@@B)
        1>main.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const Workspace::staticMetaObject" (?staticMetaObject@Workspace@@2UQMetaObject@@B)
        1>mainw.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const Workspace::staticMetaObject" (?staticMetaObject@Workspace@@2UQMetaObject@@B)
        1>mainw.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __cdecl Mainw::metaObject(void)const " (?metaObject@Mainw@@UEBAPEBUQMetaObject@@XZ)
        1>mainw.obj : error LNK2001: unresolved external symbol "public: virtual void * __cdecl Mainw::qt_metacast(char const *)" (?qt_metacast@Mainw@@UEAAPEAXPEBD@Z)
        1>mainw.obj : error LNK2001: unresolved external symbol "public: virtual int __cdecl Mainw::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@Mainw@@UEAAHW4Call@QMetaObject@@HPEAPEAX@Z)
        1>mainw.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __cdecl Workspace::metaObject(void)const " (?metaObject@Workspace@@UEBAPEBUQMetaObject@@XZ)
        1>mainw.obj : error LNK2001: unresolved external symbol "public: virtual void * __cdecl Workspace::qt_metacast(char const *)" (?qt_metacast@Workspace@@UEAAPEAXPEBD@Z)
        1>mainw.obj : error LNK2001: unresolved external symbol "public: virtual int __cdecl Workspace::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@Workspace@@UEAAHW4Call@QMetaObject@@HPEAPEAX@Z)
        

        this is my code
        mainw.h

        #include <ui_mainw.h>
        #include <ui_forcus.h>
        #include <qmainwindow.h>
        #include "control.h"
        #include "qprocess.h"
        
        class Timer;
        class control;
        
        #ifndef MAINWINDOW_H
        #define MAINWINDOW_H
        
        class Mainw : public QMainWindow {
        	Q_OBJECT
        public:
        	void start();
        	Mainw(Timer* time, QWidget* parent = nullptr);
        	~Mainw();
        signals:
        	void change_gui() {}
        private:
        	Ui::Main* ui;
        	Timer* timer;
        private slots:
        	void updatetime(long long time);
        	void toworkspace() {
        		ui->pushButton->setDisabled(true);
        		emit change_gui();
        		this->close();
        	}
        };
        
        
        
        class Workspace : public QWidget {
        	Q_OBJECT
        public:
        	Workspace(Timer* time, QWidget* parent = nullptr);
        	~Workspace();
        	void start();
        signals:
        	void change_gui() {}
        private:
        	//store all processes the ui run in a vector
        	std::vector<QProcess*> processes;
        	Ui::workspace* ui;
        	Timer* timer;
        private slots:
        	void updatetime(long long time);
        	void goback();
        };
        #endif // !MAINWINDOW_H
        

        mainw.cpp

        #include <qtimer.h>
        #include <qdatetime.h>
        #include <qmessagebox.h>
        #include "control.h"
        #include "mainw.h"
        Mainw::Mainw(Timer* time, QWidget* parent)
            :QMainWindow(parent)
            ,timer(time)
            ,ui(new Ui::Main)
        {
        	ui->setupUi(this);
        }
        
        Mainw::~Mainw() {
        	delete ui;
        }
        void Mainw::updatetime(long long time) {
            QLabel* text = ui->label;
            int hour = time / 3600;
            int minutes = time / 60;
            int second = time % 60;
            text->setText(QString("%1:%2:%3")
                .arg(hour, 2, 10, QChar('0'))
                .arg(minutes, 2, 10, QChar('0'))
                .arg(second, 2, 10, QChar('0')));
        }
        void Mainw::start() {
        
            QLabel* text = ui->label;
        	text->setText("__:__:__");
            text->setAlignment(Qt::AlignCenter);
        
            connect(timer, &Timer::requestupdated, this, &Mainw::updatetime);
        
        	connect(ui->pushButton, &QPushButton::clicked, this, &Mainw::toworkspace);
        	this->raise();
        	this->showFullScreen();
            this->show();
        }
        
        //setup Workspace
        Workspace::Workspace(Timer* time, QWidget* parent)
        	:QWidget(parent)
        	,ui(new Ui::workspace)
        	,timer(time)
        {
        	ui->setupUi(this);
        	connect(timer, &Timer::requestupdated, this, &Workspace::updatetime);
        }
        
        Workspace::~Workspace() {
        	delete ui;
        }
        
        void Workspace::start() {
        
        	//set text for timer
        
        	QLabel* text = ui->time;
        	QLabel* text2 = ui->count;
        	text->setText("__:__:__");
        	text2->setText("__:__:__");
        
        	//connect button
        
        	connect(timer, &Timer::requestupdated, this, &Workspace::updatetime);
        	QPushButton* button = ui->back;
        	connect(button, &QPushButton::clicked, this, &Workspace::goback);
        
        	//show workspace
        
        	this->raise();
        	this->showFullScreen();
        	this->show();
        }
        
        void Workspace::updatetime(long long time) {
        	//update time remain to label name "timer"
        	QLabel* text2 = ui->count;
        	int hour2 = time / 3600;
        	int minutes2 = time / 60;
        	int second2 = time % 60;
        	text2->setText(QString("%1:%2:%3")
        		.arg(hour2, 2, 10, QChar('0'))
        		.arg(minutes2, 2, 10, QChar('0'))
        		.arg(second2, 2, 10, QChar('0')));
            //update system time to label name "time"
            QLabel* text = ui->time;
        	QDateTime now = QDateTime::currentDateTime();
            text->setText(QString(now.toString("HH:mm:ss")));
        }
        
        void Workspace::goback() {
        	//show warming message if there is some proess running
        	if (processes.size() > 0) {
        		QMessageBox msgBox;
        		msgBox.setText("There is some proess running,if you exit the process will be close \ndo you want to exit?");
        		msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
        		msgBox.setDefaultButton(QMessageBox::No);
        		int ret = msgBox.exec();
        		if (ret == QMessageBox::Yes) {
        			//kill all process in vector
        			for (int i = 0; i < processes.size(); i++) {
        				processes[i]->kill();
        				delete processes[i];
        			}
        			emit change_gui();
        			this->close();
        		}
        	}
        	else {
        		emit change_gui();
        		this->close();
        	}
        }
        
        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #2

        @a_coder
        Did you run a complete rebuild/re-run qmake/cmake/delete build output directory?

        A 1 Reply Last reply
        0
        • JonBJ JonB

          @a_coder
          Did you run a complete rebuild/re-run qmake/cmake/delete build output directory?

          A Offline
          A Offline
          a_coder
          wrote on last edited by a_coder
          #3

          @JonB sorry, i build it with msvc and i tried to rebuild it but still not work

          JonBJ 1 Reply Last reply
          0
          • A a_coder

            @JonB sorry, i build it with msvc and i tried to rebuild it but still not work

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #4

            @a_coder
            It should do. moc needs to be re-run on the file containing the Q_OBJECT macro. I'm pretty sure that is what that linker error stems from. I know nothing about VS. Do you have to install a "plugin" to make it Qt-aware? In the build output filder do you have file names starting with moc_? Can you get VS to show the exact commands it is issuing when rebuilding from scratch?

            A 1 Reply Last reply
            0
            • JonBJ JonB

              @a_coder
              It should do. moc needs to be re-run on the file containing the Q_OBJECT macro. I'm pretty sure that is what that linker error stems from. I know nothing about VS. Do you have to install a "plugin" to make it Qt-aware? In the build output filder do you have file names starting with moc_? Can you get VS to show the exact commands it is issuing when rebuilding from scratch?

              A Offline
              A Offline
              a_coder
              wrote on last edited by a_coder
              #5

              @JonB i use qt extensions to link qt with visual studio and this is my msvc log when i rebuild

              Build started at 5:24 CH...
              1>------ Build started: Project: project, Configuration: Debug x64 ------
              1>Reading Qt configuration (E:/Qt/6.6.2/msvc2019_64/bin/qmake)
              1>uic workspace.ui
              1>uic mainw.ui
              1>moc mainw.h
              1>moc control.h
              1> G:\project\project\mainw.h(8:1): note: No relevant classes found. No output generated.
              1>main.cpp
              1>mainw.cpp
              1>moc_mainw.cpp
              1>moc_control.cpp
              1>main.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const Mainw::staticMetaObject" (?staticMetaObject@Mainw@@2UQMetaObject@@B)
              1>mainw.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const Mainw::staticMetaObject" (?staticMetaObject@Mainw@@2UQMetaObject@@B)
              1>main.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const Workspace::staticMetaObject" (?staticMetaObject@Workspace@@2UQMetaObject@@B)
              1>mainw.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const Workspace::staticMetaObject" (?staticMetaObject@Workspace@@2UQMetaObject@@B)
              1>mainw.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __cdecl Mainw::metaObject(void)const " (?metaObject@Mainw@@UEBAPEBUQMetaObject@@XZ)
              1>mainw.obj : error LNK2001: unresolved external symbol "public: virtual void * __cdecl Mainw::qt_metacast(char const *)" (?qt_metacast@Mainw@@UEAAPEAXPEBD@Z)
              1>mainw.obj : error LNK2001: unresolved external symbol "public: virtual int __cdecl Mainw::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@Mainw@@UEAAHW4Call@QMetaObject@@HPEAPEAX@Z)
              1>mainw.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __cdecl Workspace::metaObject(void)const " (?metaObject@Workspace@@UEBAPEBUQMetaObject@@XZ)
              1>mainw.obj : error LNK2001: unresolved external symbol "public: virtual void * __cdecl Workspace::qt_metacast(char const *)" (?qt_metacast@Workspace@@UEAAPEAXPEBD@Z)
              1>mainw.obj : error LNK2001: unresolved external symbol "public: virtual int __cdecl Workspace::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@Workspace@@UEAAHW4Call@QMetaObject@@HPEAPEAX@Z)
              1>G:\project\x64\Debug\project.exe : fatal error LNK1120: 8 unresolved externals
              1>Done building project "project.vcxproj" -- FAILED.
              ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
              ========== Build completed at 5:24 CH and took 08,659 seconds ==========
              
              JonBJ 1 Reply Last reply
              0
              • A a_coder

                @JonB i use qt extensions to link qt with visual studio and this is my msvc log when i rebuild

                Build started at 5:24 CH...
                1>------ Build started: Project: project, Configuration: Debug x64 ------
                1>Reading Qt configuration (E:/Qt/6.6.2/msvc2019_64/bin/qmake)
                1>uic workspace.ui
                1>uic mainw.ui
                1>moc mainw.h
                1>moc control.h
                1> G:\project\project\mainw.h(8:1): note: No relevant classes found. No output generated.
                1>main.cpp
                1>mainw.cpp
                1>moc_mainw.cpp
                1>moc_control.cpp
                1>main.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const Mainw::staticMetaObject" (?staticMetaObject@Mainw@@2UQMetaObject@@B)
                1>mainw.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const Mainw::staticMetaObject" (?staticMetaObject@Mainw@@2UQMetaObject@@B)
                1>main.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const Workspace::staticMetaObject" (?staticMetaObject@Workspace@@2UQMetaObject@@B)
                1>mainw.obj : error LNK2001: unresolved external symbol "public: static struct QMetaObject const Workspace::staticMetaObject" (?staticMetaObject@Workspace@@2UQMetaObject@@B)
                1>mainw.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __cdecl Mainw::metaObject(void)const " (?metaObject@Mainw@@UEBAPEBUQMetaObject@@XZ)
                1>mainw.obj : error LNK2001: unresolved external symbol "public: virtual void * __cdecl Mainw::qt_metacast(char const *)" (?qt_metacast@Mainw@@UEAAPEAXPEBD@Z)
                1>mainw.obj : error LNK2001: unresolved external symbol "public: virtual int __cdecl Mainw::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@Mainw@@UEAAHW4Call@QMetaObject@@HPEAPEAX@Z)
                1>mainw.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __cdecl Workspace::metaObject(void)const " (?metaObject@Workspace@@UEBAPEBUQMetaObject@@XZ)
                1>mainw.obj : error LNK2001: unresolved external symbol "public: virtual void * __cdecl Workspace::qt_metacast(char const *)" (?qt_metacast@Workspace@@UEAAPEAXPEBD@Z)
                1>mainw.obj : error LNK2001: unresolved external symbol "public: virtual int __cdecl Workspace::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@Workspace@@UEAAHW4Call@QMetaObject@@HPEAPEAX@Z)
                1>G:\project\x64\Debug\project.exe : fatal error LNK1120: 8 unresolved externals
                1>Done building project "project.vcxproj" -- FAILED.
                ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
                ========== Build completed at 5:24 CH and took 08,659 seconds ==========
                
                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #6

                @a_coder said in unresolved external symbol "public: static struct QMetaObject const staticMetaObject":

                G:\project\project\mainw.h(8:1): note: No relevant classes found. No output generated.

                I think this looks to be the issue to me. If that indicates that moc did not think your mainw.h did not have recognisable Q_OBJECT macros that would be a problem. I think your mainw.h does have these correctly, so I'm not sure why, but assume the error message is telling us it's a problem.

                You have done some hand-coding here, and some if it is not right. For example,:

                • Any #ifndef MAINWINDOW_H should be right at the start of the header, but you have preceded it by your own '#includes. Though I don't think this would cause your error. But it might do if you have done this in other .h files like control.h.

                • You use <...> in #include <ui_mainw.h>, but you should not. It is not a "system" include. It should be #include "ui_mainw.h". But again I don't think this would cause your error (though you should change it nonetheless, if there is then a problem something is wrong).

                • You have #include <ui_forcus.h> in mainw.h. But ui_....h files are only for including into their corresponding .cpp file. This is more worrying, I don't know what effect that might have.

                If you cannot get past this, I would suggest you reduce your project to only having the Mainw class. Stop including/compiling/linking anything but the ...mainw... files. And although it should work to have multiple Q_OBJECT classes in your mainw.h file you might get rid of the extra Workspace class while you are having the problem. Get that working. Then add back in the other stuff. You could create a brand new, standalone project with nothing but a MainWindow form and verify that links correctly.

                A 1 Reply Last reply
                1
                • JonBJ JonB

                  @a_coder said in unresolved external symbol "public: static struct QMetaObject const staticMetaObject":

                  G:\project\project\mainw.h(8:1): note: No relevant classes found. No output generated.

                  I think this looks to be the issue to me. If that indicates that moc did not think your mainw.h did not have recognisable Q_OBJECT macros that would be a problem. I think your mainw.h does have these correctly, so I'm not sure why, but assume the error message is telling us it's a problem.

                  You have done some hand-coding here, and some if it is not right. For example,:

                  • Any #ifndef MAINWINDOW_H should be right at the start of the header, but you have preceded it by your own '#includes. Though I don't think this would cause your error. But it might do if you have done this in other .h files like control.h.

                  • You use <...> in #include <ui_mainw.h>, but you should not. It is not a "system" include. It should be #include "ui_mainw.h". But again I don't think this would cause your error (though you should change it nonetheless, if there is then a problem something is wrong).

                  • You have #include <ui_forcus.h> in mainw.h. But ui_....h files are only for including into their corresponding .cpp file. This is more worrying, I don't know what effect that might have.

                  If you cannot get past this, I would suggest you reduce your project to only having the Mainw class. Stop including/compiling/linking anything but the ...mainw... files. And although it should work to have multiple Q_OBJECT classes in your mainw.h file you might get rid of the extra Workspace class while you are having the problem. Get that working. Then add back in the other stuff. You could create a brand new, standalone project with nothing but a MainWindow form and verify that links correctly.

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

                  @JonB can i put many gui in one .ui file?

                  Christian EhrlicherC 1 Reply Last reply
                  0
                  • A a_coder

                    @JonB can i put many gui in one .ui file?

                    Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #8

                    @a_coder what has this to do with the problem? Make sure you don't have a second header file named the same way somewhere around.

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    A 1 Reply Last reply
                    1
                    • Christian EhrlicherC Christian Ehrlicher

                      @a_coder what has this to do with the problem? Make sure you don't have a second header file named the same way somewhere around.

                      A Offline
                      A Offline
                      a_coder
                      wrote on last edited by
                      #9

                      @Christian-Ehrlicher of course i don’t have another one named same

                      Christian EhrlicherC 1 Reply Last reply
                      0
                      • A a_coder

                        @Christian-Ehrlicher of course i don’t have another one named same

                        Christian EhrlicherC Offline
                        Christian EhrlicherC Offline
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on last edited by
                        #10

                        @a_coder then cleanup your include and move the ifdef to the top

                        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                        Visit the Qt Academy at https://academy.qt.io/catalog

                        1 Reply Last reply
                        0
                        • A Offline
                          A Offline
                          a_coder
                          wrote on last edited by
                          #11

                          after some edit of my code i think i fixed it but i got some another errors:

                          1>G:\project\project\control.h(76,7): error C2143: syntax error: missing ';' before '*'
                          1>(compiling source file 'x64/Debug/moc/moc_mainw.cpp')
                          1>G:\project\project\control.h(76,7): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
                          1>(compiling source file 'x64/Debug/moc/moc_mainw.cpp')
                          1>G:\project\project\control.h(76,14): error C2238: unexpected token(s) preceding ';'
                          1>(compiling source file 'x64/Debug/moc/moc_mainw.cpp')
                          1>G:\project\project\control.h(50,15): error C2061: syntax error: identifier 'Mainw'
                          1>(compiling source file 'x64/Debug/moc/moc_mainw.cpp')
                          1>G:\project\project\control.h(50,27): error C2612: trailing ')' illegal in base/member initializer list
                          1>(compiling source file 'x64/Debug/moc/moc_mainw.cpp')
                          1>G:\project\project\mainw.h(12,2): warning C4081: expected ')'; found 'string'
                          1>(compiling source file 'x64/Debug/moc/moc_mainw.cpp')
                          1>G:\project\project\x64\Debug\moc\moc_mainw.cpp(32,1): warning C4081: expected ')'; found 'string'
                          1>G:\project\project\x64\Debug\moc\moc_mainw.cpp(160,1): error C1004: unexpected end-of-file found
                          1>Done building project "project.vcxproj" -- FAILED.
                          1>Done building project "project.vcxproj" -- FAILED.
                          

                          i think workspace and mainw class isn't defined in control class although i inclued it
                          my control.h

                          #ifndef CONTROLER_H
                          #define CONTROLER_H
                          
                          #include <qobject.h>
                          #include <qtimer.h>
                          #include <qobject.h>
                          #include "mainw.h"
                          #include "workspace.h"
                          
                          
                          class Timer :public QObject {
                          	Q_OBJECT
                          public:
                          	Timer(long long &timesetup, QObject* parent = nullptr)
                          		:QObject(parent)
                          		,counter(new QTimer)
                          	{
                          		timereaining = &timesetup;
                          		connect(counter, &QTimer::timeout, this, &Timer::sendupdate);
                          	}
                          	void start() {
                          		counter->setInterval(1000);
                          		counter->start();
                          	}
                          signals:
                          	void requestupdated(long long remainsecond);
                          	void timeout();
                          private slots:
                          	void sendupdate() {
                          		if (*timereaining <= 0) {
                          			emit timeout();
                          		}
                          		else {
                          			(*timereaining)--;
                          			emit requestupdated(*timereaining);
                          		}
                          	}
                          private:
                          	long long* timereaining;
                          	QTimer* counter;
                          };
                          
                          class control :public QObject {
                          	Q_OBJECT
                          public:
                          	control(Timer* time, QObject* parent = nullptr):
                          		QObject(parent)
                          		,timer(time)
                          		, workspace(new Workspace(timer))
                          		, mainw(new Mainw(timer))
                          	{
                          		/*mainw = new Mainw(timer);
                          		workspace = new Workspace(timer);*/
                          	}
                          	~control() {
                          	}
                          	void start() {
                          		connect(mainw, &Mainw::change_gui, this, &control::changeto_workspace_slot);
                          		connect(workspace, &Workspace::change_gui, this, &control::changeto_mainw_slot);
                          		mainw->start();
                          	}
                          //signals:
                          	//void changeto_mainw();
                          	//void changeto_workspace();
                          private slots:
                          	void changeto_mainw_slot() {
                          		mainw->start();
                          		workspace->close();
                          	}
                          	void changeto_workspace_slot() {
                          		workspace->start();
                          		mainw->close();
                          	}
                          private:
                          	Timer* timer;
                          	Mainw* mainw;
                          	Workspace* workspace;
                          };
                          #endif // CONTROLER_H
                          

                          and i detached mainw and workspace and put it to different header file

                          jsulmJ 1 Reply Last reply
                          0
                          • A a_coder

                            after some edit of my code i think i fixed it but i got some another errors:

                            1>G:\project\project\control.h(76,7): error C2143: syntax error: missing ';' before '*'
                            1>(compiling source file 'x64/Debug/moc/moc_mainw.cpp')
                            1>G:\project\project\control.h(76,7): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
                            1>(compiling source file 'x64/Debug/moc/moc_mainw.cpp')
                            1>G:\project\project\control.h(76,14): error C2238: unexpected token(s) preceding ';'
                            1>(compiling source file 'x64/Debug/moc/moc_mainw.cpp')
                            1>G:\project\project\control.h(50,15): error C2061: syntax error: identifier 'Mainw'
                            1>(compiling source file 'x64/Debug/moc/moc_mainw.cpp')
                            1>G:\project\project\control.h(50,27): error C2612: trailing ')' illegal in base/member initializer list
                            1>(compiling source file 'x64/Debug/moc/moc_mainw.cpp')
                            1>G:\project\project\mainw.h(12,2): warning C4081: expected ')'; found 'string'
                            1>(compiling source file 'x64/Debug/moc/moc_mainw.cpp')
                            1>G:\project\project\x64\Debug\moc\moc_mainw.cpp(32,1): warning C4081: expected ')'; found 'string'
                            1>G:\project\project\x64\Debug\moc\moc_mainw.cpp(160,1): error C1004: unexpected end-of-file found
                            1>Done building project "project.vcxproj" -- FAILED.
                            1>Done building project "project.vcxproj" -- FAILED.
                            

                            i think workspace and mainw class isn't defined in control class although i inclued it
                            my control.h

                            #ifndef CONTROLER_H
                            #define CONTROLER_H
                            
                            #include <qobject.h>
                            #include <qtimer.h>
                            #include <qobject.h>
                            #include "mainw.h"
                            #include "workspace.h"
                            
                            
                            class Timer :public QObject {
                            	Q_OBJECT
                            public:
                            	Timer(long long &timesetup, QObject* parent = nullptr)
                            		:QObject(parent)
                            		,counter(new QTimer)
                            	{
                            		timereaining = &timesetup;
                            		connect(counter, &QTimer::timeout, this, &Timer::sendupdate);
                            	}
                            	void start() {
                            		counter->setInterval(1000);
                            		counter->start();
                            	}
                            signals:
                            	void requestupdated(long long remainsecond);
                            	void timeout();
                            private slots:
                            	void sendupdate() {
                            		if (*timereaining <= 0) {
                            			emit timeout();
                            		}
                            		else {
                            			(*timereaining)--;
                            			emit requestupdated(*timereaining);
                            		}
                            	}
                            private:
                            	long long* timereaining;
                            	QTimer* counter;
                            };
                            
                            class control :public QObject {
                            	Q_OBJECT
                            public:
                            	control(Timer* time, QObject* parent = nullptr):
                            		QObject(parent)
                            		,timer(time)
                            		, workspace(new Workspace(timer))
                            		, mainw(new Mainw(timer))
                            	{
                            		/*mainw = new Mainw(timer);
                            		workspace = new Workspace(timer);*/
                            	}
                            	~control() {
                            	}
                            	void start() {
                            		connect(mainw, &Mainw::change_gui, this, &control::changeto_workspace_slot);
                            		connect(workspace, &Workspace::change_gui, this, &control::changeto_mainw_slot);
                            		mainw->start();
                            	}
                            //signals:
                            	//void changeto_mainw();
                            	//void changeto_workspace();
                            private slots:
                            	void changeto_mainw_slot() {
                            		mainw->start();
                            		workspace->close();
                            	}
                            	void changeto_workspace_slot() {
                            		workspace->start();
                            		mainw->close();
                            	}
                            private:
                            	Timer* timer;
                            	Mainw* mainw;
                            	Workspace* workspace;
                            };
                            #endif // CONTROLER_H
                            

                            and i detached mainw and workspace and put it to different header file

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

                            @a_coder said in unresolved external symbol "public: static struct QMetaObject const staticMetaObject":

                            1>G:\project\project\control.h(76,7): error C2143: syntax error: missing ';' before '*'
                            1>(compiling source file 'x64/Debug/moc/moc_mainw.cpp')
                            1>G:\project\project\control.h(76,7): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
                            1>(compiling source file 'x64/Debug/moc/moc_mainw.cpp')

                            So, what is in these lines in control.h?
                            And what is the very first error?

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

                            Christian EhrlicherC 1 Reply Last reply
                            0
                            • jsulmJ jsulm

                              @a_coder said in unresolved external symbol "public: static struct QMetaObject const staticMetaObject":

                              1>G:\project\project\control.h(76,7): error C2143: syntax error: missing ';' before '*'
                              1>(compiling source file 'x64/Debug/moc/moc_mainw.cpp')
                              1>G:\project\project\control.h(76,7): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
                              1>(compiling source file 'x64/Debug/moc/moc_mainw.cpp')

                              So, what is in these lines in control.h?
                              And what is the very first error?

                              Christian EhrlicherC Offline
                              Christian EhrlicherC Offline
                              Christian Ehrlicher
                              Lifetime Qt Champion
                              wrote on last edited by
                              #13

                              apart from the really strange usage of reference and pointers to this reference which will likely not work, don't use 'long long' in signals and slots (or any other 'composed' type as e.g. unsigned int)

                              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                              Visit the Qt Academy at https://academy.qt.io/catalog

                              A 1 Reply Last reply
                              0
                              • Christian EhrlicherC Christian Ehrlicher

                                apart from the really strange usage of reference and pointers to this reference which will likely not work, don't use 'long long' in signals and slots (or any other 'composed' type as e.g. unsigned int)

                                A Offline
                                A Offline
                                a_coder
                                wrote on last edited by
                                #14

                                @Christian-Ehrlicher which vaule i can use in signal and slots?

                                Christian EhrlicherC 1 Reply Last reply
                                0
                                • A a_coder

                                  @Christian-Ehrlicher which vaule i can use in signal and slots?

                                  Christian EhrlicherC Offline
                                  Christian EhrlicherC Offline
                                  Christian Ehrlicher
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #15

                                  @a_coder said in unresolved external symbol "public: static struct QMetaObject const staticMetaObject":

                                  which vaule i can use in signal and slots?

                                  How should I know which value you send through signals and slot. If you want which datatype then, as I already said, anything which consists of only one word to not confuse the moc compiler.

                                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                                  Visit the Qt Academy at https://academy.qt.io/catalog

                                  A 1 Reply Last reply
                                  0
                                  • Christian EhrlicherC Christian Ehrlicher

                                    @a_coder said in unresolved external symbol "public: static struct QMetaObject const staticMetaObject":

                                    which vaule i can use in signal and slots?

                                    How should I know which value you send through signals and slot. If you want which datatype then, as I already said, anything which consists of only one word to not confuse the moc compiler.

                                    A Offline
                                    A Offline
                                    a_coder
                                    wrote on last edited by a_coder
                                    #16

                                    @Christian-Ehrlicher i want to synchronized my countdown from two windows so i send the signal with the time remain in there.however, i don't think that will make the code error

                                    JonBJ 1 Reply Last reply
                                    0
                                    • A a_coder

                                      @Christian-Ehrlicher i want to synchronized my countdown from two windows so i send the signal with the time remain in there.however, i don't think that will make the code error

                                      JonBJ Offline
                                      JonBJ Offline
                                      JonB
                                      wrote on last edited by
                                      #17

                                      @a_coder
                                      @Christian-Ehrlicher has suggested you do not use a type written as e.g. long long as a signal parameter, as moc may not like it. I don't know, but I would try obeying his hint and change that to see if it helps.

                                      A 1 Reply Last reply
                                      0
                                      • JonBJ JonB

                                        @a_coder
                                        @Christian-Ehrlicher has suggested you do not use a type written as e.g. long long as a signal parameter, as moc may not like it. I don't know, but I would try obeying his hint and change that to see if it helps.

                                        A Offline
                                        A Offline
                                        a_coder
                                        wrote on last edited by
                                        #18

                                        @JonB now i removed long long in signal and it will get that in Timer class but i still got some errors

                                        Build started at 8:33 CH...
                                        1>------ Build started: Project: project, Configuration: Debug x64 ------
                                        1>Reading Qt configuration (E:/Qt/6.7.0/msvc2019_64/bin/qmake)
                                        1>uic mainw.ui
                                        1>uic workspace.ui
                                        1>moc control.h
                                        1>moc mainw.h
                                        1>moc workspace.h
                                        1>main.cpp
                                        1>mainw.cpp
                                        1>workspace.cpp
                                        1>moc_control.cpp
                                        1>moc_mainw.cpp
                                        1>G:\project\project\control.h(77,7): error C2143: syntax error: missing ';' before '*'
                                        1>(compiling source file 'x64/Debug/moc/moc_mainw.cpp')
                                        1>G:\project\project\control.h(77,7): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
                                        1>(compiling source file 'x64/Debug/moc/moc_mainw.cpp')
                                        1>G:\project\project\control.h(77,14): error C2238: unexpected token(s) preceding ';'
                                        1>(compiling source file 'x64/Debug/moc/moc_mainw.cpp')
                                        1>G:\project\project\control.h(51,15): error C2061: syntax error: identifier 'Mainw'
                                        1>(compiling source file 'x64/Debug/moc/moc_mainw.cpp')
                                        1>G:\project\project\control.h(51,27): error C2612: trailing ')' illegal in base/member initializer list
                                        1>(compiling source file 'x64/Debug/moc/moc_mainw.cpp')
                                        1>G:\project\project\mainw.h(12,2): warning C4081: expected ')'; found 'string'
                                        1>(compiling source file 'x64/Debug/moc/moc_mainw.cpp')
                                        1>G:\project\project\x64\Debug\moc\moc_mainw.cpp(32,1): warning C4081: expected ')'; found 'string'
                                        1>G:\project\project\x64\Debug\moc\moc_mainw.cpp(159,1): error C1004: unexpected end-of-file found
                                        1>Done building project "project.vcxproj" -- FAILED.
                                        ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
                                        ========== Build completed at 8:33 CH and took 11,009 seconds ==========
                                        
                                        jsulmJ 1 Reply Last reply
                                        0
                                        • A a_coder

                                          @JonB now i removed long long in signal and it will get that in Timer class but i still got some errors

                                          Build started at 8:33 CH...
                                          1>------ Build started: Project: project, Configuration: Debug x64 ------
                                          1>Reading Qt configuration (E:/Qt/6.7.0/msvc2019_64/bin/qmake)
                                          1>uic mainw.ui
                                          1>uic workspace.ui
                                          1>moc control.h
                                          1>moc mainw.h
                                          1>moc workspace.h
                                          1>main.cpp
                                          1>mainw.cpp
                                          1>workspace.cpp
                                          1>moc_control.cpp
                                          1>moc_mainw.cpp
                                          1>G:\project\project\control.h(77,7): error C2143: syntax error: missing ';' before '*'
                                          1>(compiling source file 'x64/Debug/moc/moc_mainw.cpp')
                                          1>G:\project\project\control.h(77,7): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
                                          1>(compiling source file 'x64/Debug/moc/moc_mainw.cpp')
                                          1>G:\project\project\control.h(77,14): error C2238: unexpected token(s) preceding ';'
                                          1>(compiling source file 'x64/Debug/moc/moc_mainw.cpp')
                                          1>G:\project\project\control.h(51,15): error C2061: syntax error: identifier 'Mainw'
                                          1>(compiling source file 'x64/Debug/moc/moc_mainw.cpp')
                                          1>G:\project\project\control.h(51,27): error C2612: trailing ')' illegal in base/member initializer list
                                          1>(compiling source file 'x64/Debug/moc/moc_mainw.cpp')
                                          1>G:\project\project\mainw.h(12,2): warning C4081: expected ')'; found 'string'
                                          1>(compiling source file 'x64/Debug/moc/moc_mainw.cpp')
                                          1>G:\project\project\x64\Debug\moc\moc_mainw.cpp(32,1): warning C4081: expected ')'; found 'string'
                                          1>G:\project\project\x64\Debug\moc\moc_mainw.cpp(159,1): error C1004: unexpected end-of-file found
                                          1>Done building project "project.vcxproj" -- FAILED.
                                          ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
                                          ========== Build completed at 8:33 CH and took 11,009 seconds ==========
                                          
                                          jsulmJ Offline
                                          jsulmJ Offline
                                          jsulm
                                          Lifetime Qt Champion
                                          wrote on last edited by
                                          #19

                                          @a_coder Please post current control.h and also mark the line 77 there

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

                                          1 Reply Last reply
                                          1
                                          • A Offline
                                            A Offline
                                            a_coder
                                            wrote on last edited by
                                            #20

                                            @jsulm

                                            #ifndef CONTROLER_H
                                            #define CONTROLER_H
                                            
                                            #include <qobject.h>
                                            #include <qtimer.h>
                                            #include <qobject.h>
                                            #include "mainw.h"
                                            #include "workspace.h"
                                            
                                            
                                            class Timer :public QObject {
                                            	Q_OBJECT
                                            public:
                                            	Timer(long long &timesetup, QObject* parent = nullptr)
                                            		:QObject(parent)
                                            		,counter(new QTimer)
                                            	{
                                            		timereaining = &timesetup;
                                            		connect(counter, &QTimer::timeout, this, &Timer::sendupdate);
                                            	}
                                            	long long timeleft() { return *timereaining; }
                                            	void start() {
                                            		counter->setInterval(1000);
                                            		counter->start();
                                            	}
                                            signals:
                                            	void requestupdated();
                                            	void timeout();
                                            private slots:
                                            	void sendupdate() {
                                            		if (*timereaining <= 0) {
                                            			emit timeout();
                                            		}
                                            		else {
                                            			(*timereaining)--;
                                            			emit requestupdated();
                                            		}
                                            	}
                                            private:
                                            	long long* timereaining;
                                            	QTimer* counter;
                                            };
                                            
                                            class control :public QObject {
                                            	Q_OBJECT
                                            public:
                                            	control(Timer* time, QObject* parent = nullptr):
                                            		QObject(parent)
                                            		,timer(time)
                                            		, workspace(new Workspace(timer))
                                            		, mainw(new Mainw(timer))
                                            	{
                                            		/*mainw = new Mainw(timer);
                                            		workspace = new Workspace(timer);*/
                                            	}
                                            	~control() {
                                            	}
                                            	void start() {
                                            		connect(mainw, &Mainw::change_gui, this, &control::changeto_workspace_slot);
                                            		connect(workspace, &Workspace::change_gui, this, &control::changeto_mainw_slot);
                                            		mainw->start();
                                            	}
                                            //signals:
                                            	//void changeto_mainw();
                                            	//void changeto_workspace();
                                            private slots:
                                            	void changeto_mainw_slot() {
                                            		mainw->start();
                                            		workspace->close();
                                            	}
                                            	void changeto_workspace_slot() {
                                            		workspace->start();
                                            		mainw->close();
                                            	}
                                            private:
                                            	Timer* timer;
                                            	Mainw* mainw; //line 77
                                            	Workspace* workspace;
                                            };
                                            #endif // CONTROLER_H 
                                            

                                            sorry idk how to mark that

                                            jsulmJ 2 Replies 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