Re: Error message in QThread
Move the QMessageBox to the Main thread, and send a signal to the QMessageBox from the separate tread.
This is how it is supposed to be used, all GUI components should be in main thread only.
Re: Error message in QThread
Sorry for my ignorant. But how do you send a signal from a separate thread?
I can understand we should only use the Qmessagebox in the main thread. But
cant figure out how do I send a signal from the thread?
Re: Error message in QThread
Refer this example to send signals to Main (GUI) thread from QThread
http://www.qtcentre.org/wiki/index.p...I_from_QThread
Re: Error message in QThread
Thanks.
I followed the example but gotten this error during linking.
LNK2019:unresolved external symbol"protected: void __thiscall mythread:valuceChanged(int)"
What I dont get is, this valueChanged is the standard function for signals.
So, do I have to define it again in my own function?
And the example didnt show that we need to define this valueChanged function either.
Any help?
Re: Error message in QThread
Please take a look again at the example in the link that Santosh has provided. There is "Source Files" section, where you have this simple mechanism of connection signals to slots implemented. If you look more closely you will see that valueChanged is a custom signal of MyThread class. Now you have to define your own signal in your own thread.
Re: Error message in QThread
Thanks.
Sorry, but I've been looking at the files and also downloaded them and view them again and again.
There is no indication of how do you and where did it define the valueChanged.
I read that there is the
1. signals:
void valueChanged(int);
2. emit valueChanged(i);
But there is nothing on how do you define this valueChanged function. Do we need the metaobject to define it?
If I compile this, I'll get the error - LNK2019:unresolved external symbol"protected: void __thiscall mythread:valuceChanged(int)".
I'm still confused...
Re: Error message in QThread
valueChanged is a signal, and you don't provide implementation of signals, moc does.
Be sure to do a clean build (make clean, qmake, make). Check if moc code is generated for your class (dont forget Q_OBJECT macro).
Re: Error message in QThread
Hi.
I did a clean and rebuild. I also make sure I've Q_Object macro in mythread.
Now I got the following errors. Before I added Q_Object, I've only the LNK2019 error.
Also, can you confirm that even for custom signals like the earlier author Rachol replied,
that I still do not need to provide implementation of the valueChanged function?
If so, how do I resolve these metaobject error below?
Please help. I'm losing my hair over this and cant move on.
Code:
mythread.obj:-1: error: LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall mythread::metaObject(void)const " (?metaObject@mythread@@UBEPBUQMetaObject@@XZ)
mythread.obj:-1: error: LNK2001: unresolved external symbol "public: virtual void * __thiscall mythread::qt_metacast(char const *)" (?qt_metacast@mythread@@UAEPAXPBD@Z)
mythread.
obj:-1: error
: LNK2001
: unresolved external symbol
"public: virtual int __thiscall mythread::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@mythread@@UAEHW4Call@
QMetaObject@@HPAPAX@Z
)mythread.obj:-1: error: LNK2019: unresolved external symbol "protected: void __thiscall mythread::valueChanged(int)" (?valueChanged@mythread@@IAEXH@Z) referenced in function "public: void __thiscall mythread::init(void)" (?init@mythread@@QAEXXZ)
mythread.obj:-1: error: LNK2001: unresolved external symbol "public: static struct QMetaObject const mythread::staticMetaObject" (?staticMetaObject@mythread@@2UQMetaObject@@B)
Re: Error message in QThread
You do not provide implementation of any signals, because moc will do that. You need to implement slots if you have any.
This looks like moc code is not compiled, how do you build your project ? If you have a .pro file, post it here. Show the header too, maybe you have some obvious errors, typos etc.
Re: Error message in QThread
Hi.
Below is my .pro file.
I'm using QT creator as my IDE.
Yes. I've implemented my slots.
I think you're right. I'm missing the moc codes.
So, how do I ask QT creator to build moc codes?
Code:
#-------------------------------------------------
#
# Project created by QtCreator 2011-04-25T10:51:02
#
#-------------------------------------------------
QT += core gui
TARGET = mylittleProgram
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
mylittleheader.cpp \
mylittlerender.cpp \
mylittlereaddata.cpp \
mythread.cpp
HEADERS += mainwindow.h \
mylittleheader.h \
mylittlerender.h \
mylittlereaddata.h \
mythread.h
FORMS += mainwindow.ui
Re: Error message in QThread
It should do it automatically.
.pro file looks ok, so I'd start by running qmake and check if Makefiles contains correct moc build targets.