You don't need to make a .moc file, the #include statement on it's own is sufficient.
You don't need to make a .moc file, the #include statement on it's own is sufficient.
Did you set your path? Installing Qt on Windows
I went to Control Panel|System|Advance System Settings | Environmental Variables...|Path then typed in c:/qt/4.6.2/bin and nothing new happened.
I downloaded Qt for windows out of curiosity. During the installation I told it to install in a directory named "d:/qt". The moc executable (moc.exe) ended up in "d:/qt/qt/bin". There is also a "d:/qt/bin". So your path might be "c:/qt/4.6.2/qt/bin". Check to see where "moc.exe" is on your machine and put that in your path.
Since the windows sdk is build with two different compilers ":/qt/4.6.2/bin" is only for Qt creator, whereas :/qt/4.6.2/qt/bin is the normal bin directory of Qt.
No matter what I do this still happens, maybe someone could attach a video to show me what to do.
Well, i'm a brazilian guy !
So, excuses goes for my poor english.
My first contact with trolls and qt, was in february 2010. I am a very very very newbie.
I am now, just wating the result of this thread.
It is because i have installed qt creator into a linux (fedora 12) box, and noted the same situation described here.
just proceed as follow
1- Start a new EMPTY qt project.
2 - Add main.cpp
3 - Subclass any qt class and use QT_OBJECT macro.
4. build
The same error will ocurr.
But if i start a non-empty project, delete all files, and then re-start adding main.cpp, the build goes right.
Someone has any clue ?
fe
This works for me, please attach your project where this error occurs.
I must reformulate my post, because i was totally wrong.
The error occurs *ONLY* if i subclass inside main.cpp.
Today a just started a empty Qt project an typed the following "do nothing" main.cpp :
#include <QApplication>
#include "SubclassE.h"
class SubclassI : public QWidget
{
Q_OBJECT
public:
SubclassI(QWidget *parent = 0) : QWidget(parent) {} ;
} ;
int main(int argc, char *argv[])
{
SubclassE e ;
SubclassI i ;
QApplication a(argc, argv);
return a.exec();
}
The SubclassE.h defines a class similar to SubclassI defined in the main.cpp. Here is my SubclassE.h
#ifndef SUBCLASSE_H
#define SUBCLASSE_H
#include <QWidget>
class SubclassE : public QWidget
{
Q_OBJECT
public:
SubclassE(QWidget *parent = 0) : QWidget(parent) {} ;
} ;
#endif // SUBCLASSE_H
Then, when i build, the SubclassE pass through the compiler, but SubclassI (defined into main.cpp) generates
the error :
undefined reference to 'vtable SubclassI'
I searched into examples code by a project that uses a subclass with Q_OBJECT macro inside main.cpp.
I found moveblocks.
The strange fact is that moveblocks compilation generates no errors. I saw a main.moc after the moveblocks build. That file is not generated when i build my own project. But a moc_SubclassE.cpp was generated.
Now, the question really is :
Why no main.moc is generated after my build ?
thanks,
fe.
PS : I don't know how to put the code inside this box with that amazing colors and scrollbar.
For full example, the following main.cpp will both compile and link. Your SubclassE.h does not need to be modified.
Qt Code:
#include <QApplication> #include "SubclassE.h" { Q_OBJECT public: } ; int main(int argc, char *argv[]) { SubclassE e ; SubclassI i ; return a.exec(); } #include "main.moc"To copy to clipboard, switch view to plain text mode
When run, it produces the following:
Qt Code:
Starting example.exe...To copy to clipboard, switch view to plain text mode
Which is expected, as you attempt to create an instance of SubclassE and SubclassI before QApplication.
@bijan311 - Please post the start up screen for your Qt Command Prompt. Qt_prompt.jpg
Yeah !
Thanks norobro !
I put the #include "main.moc" and build tell me that main.moc was not found.
Then i clean the project, run qmake and rebuild it.
There is no error now.
ok, here you go.
I have no idea why the thing on top is green, its usually blue
Why is Qt trying to add the codeblocks directory to the PATH?
Maybe it's trying to use the wrong version of gcc?
A bit heavy handed, but have you tried uninstalling CodeBlocks and then reinstalling the Qt SDK and then using Qt Creator on your project?
Sorry bijan311 I've just been shooting in the dark. I haven't used windows for several years and this is my first stab at using Qt under windows. Heck I had to squirt a little wd40 onto my winxp to get it to boot
Looks to me like the path still isn't right. Notice that my path is set to d:\Qt\4.6.2\qt\bin. That's where moc.exe resides on my system. I have no idea how it was set if changing the path in environment variables didn't change yours.
Fatjuicymole is a windows user so I'd follow his advice.
My post is a complete stab in the dark too, but it just seems weird that since Qt comes with GCC, why it would use the GCC in the Codeblocks directory.
Maybe because my MinGW installment is in the Codeblocks directory
Ok I found "main.moc" in the debug folder so I copied that into the folder that main.cpp is in, but when i compiles and i press execute the LCDNumber doesn't change.
here is my code
Qt Code:
#include <QApplication> #include <QPushButton> #include <QLabel> #include <QSpinBox> #include <QLCDNumber> #include <QHBoxLayout> #include <QVBoxLayout> Q_OBJECT public: layout->addWidget(num1); layout->addWidget(minus); layout->addWidget(num2); layout->addWidget(answer); buttons->addStretch(); buttons->addWidget(equal); buttons->addStretch(); mainLayout->addLayout(layout); mainLayout->addLayout(buttons); } public slots: void calculate() { answer->display(num1->value()-num2->value()); disconnect(); } private: QLabel *minus; QPushButton *equal; QPushButton *help; QSpinBox *num1; QSpinBox *num2; QLCDNumber *answer; }; int main(int argc, char **argv){ Calculator w; w.show(); return app.exec(); } #include "main.moc"To copy to clipboard, switch view to plain text mode
Your connect call is still wrong. Your answer object doesn't have a slot called calculate.
Bookmarks