| Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date | |
| All threads index page 4 | |
hi,
i want to emit signal in qthread ,this is my code
class myThread:public QThread
{
int val;
void setValue(int a){
....................
val=a;
emit valueChanged(val);
}
signals:
void valueChanged(int);
};
and
class myApps:public QObject
{
.........................
signals:
void anotherValueChanged(int);
};
myApps::myApps()
{
myThread *thread=new myThread();
connect(thread,SIGNAL(valueChanged(int)),this,SIGNAL(anotherValueChanged(int)));
...........
}
and gcc complains:
myapps.cc: In constructor 'myApps::myApps()':
myapps.cc:13: error: no matching function for call to
'myApps::connect(myThread*&, const char [24], myApps* const, const
char [23])'
/usr/lib/qt/include/qobject.h:116: note: candidates are: static bool
QObject::connect(const QObject*, const char*, const QObject*, const
char*)
/usr/lib/qt/include/qobject.h:226: note: bool
QObject::connect(const QObject*, const char*, const char*) const
make: *** [myapps.o] Error 1
the qt doc said can use signals and slots in thread,why this error?
what's problem?
thanks
--
[ signature omitted ]
On Monday 14 May 2007, jiang jefix wrote: > hi, > i want to emit signal in qthread ,this is my code [cut] This code was definitely not compileable. But you are in luck, because this is a very typical error: > and gcc complains: > myapps.cc: In constructor 'myApps::myApps()': > myapps.cc:13: error: no matching function for call to > 'myApps::connect(myThread*&, const char [24], myApps* const, const > char [23])' These lines tell you what you tried to do and that GCC does not know a method/function that matches this pattern. Next it offers you some possibilities: > /usr/lib/qt/include/qobject.h:116: note: candidates are: static bool > QObject::connect(const QObject*, const char*, const QObject*, const > char*) > /usr/lib/qt/include/qobject.h:226: note: bool > QObject::connect(const QObject*, const char*, const char*) const > make: *** [myapps.o] Error 1 A very basic listing of all connect methods it knows about. Had you included <sys/socket.h> it would try to be funny and offer a third one: /usr/include/sys/socket.h:???: note: extern "C" int ::connect(int,const struct sockaddr*, socklen_t) > the qt doc said can use signals and slots in thread,why this error? > what's problem? The docu is correct. But your compiler has a problem knowing this. The choice you wanted the compiler to make was the first one: static bool QObject::connect(const QObject*, const char*, const QObject*, const char*) For some reason it felt unable to do so. Now ask yourself: "why?" Let's go through all the arguments you gave: connect(thread,SIGNAL(valueChanged(int)),this,SIGNAL(anotherValueChanged(int))) 1) thread is pointer to myThread inherits QThread inherits QObject; so it should match const QObject* 2) a SIGNAL-macro; matches const char* 3) this is const myApps*, inherits QObject; hence should match const QObject* 4) a SIGNAL-macro; matches const char* Test number two: does your compiler know it is like this? 2 and 4 are trivial: it already tells you it resolved to const char[something] 1 and 3 are trickier: did you really include all necessary header files that declare these classes? I'd guess no, because this error means GCC does not know that myThread*& and myApps* are equivalent to QObject*. If the code you quoted really comes from your real code, then I'd venture that this line also generated an error: myThread *thread=new myThread(); GCC can't possibly know how to instantiate a myThread if it doesn't even know it is derived from QThread/QObject. Something about style: you start class names with lower-case letters. This is very confusing, since you really can't see immediately what is a class and what is a variable. Something else about style: try at least to use upper case letters in your English language sentences. It shows some respect. I would have skipped your mail for that if this had not been such a good opportunity to brag about my GCC-knowledge to the rest of the list... ;-) Konrad
Attachment:
Attachment:
pgpfMOKO3xH48.pgp
Description: PGP signature
Message 3 in thread
Thanks very much for your detail reply and polite-about sugesstions.
2007/5/14, Konrad Rosenbaum <konrad@xxxxxxxxx>:
> [cut]
>
> This code was definitely not compileable.
>
> But you are in luck, because this is a very typical error:
>
> These lines tell you what you tried to do and that GCC does not know a
> method/function that matches this pattern.
>
> Next it offers you some possibilities:
>
>
> A very basic listing of all connect methods it knows about. Had you included
> <sys/socket.h> it would try to be funny and offer a third one:
>
> /usr/include/sys/socket.h:???: note:
> extern "C" int ::connect(int,const struct sockaddr*, socklen_t)
>
>
>
> The docu is correct. But your compiler has a problem knowing this.
>
> The choice you wanted the compiler to make was the first one:
> static bool QObject::connect(const QObject*, const char*, const QObject*,
> const char*)
>
> For some reason it felt unable to do so. Now ask yourself: "why?"
>
> Let's go through all the arguments you gave:
> connect(thread,SIGNAL(valueChanged(int)),this,SIGNAL(anotherValueChanged(int)))
>
> 1) thread is pointer to myThread inherits QThread inherits QObject; so it
> should match const QObject*
>
> 2) a SIGNAL-macro; matches const char*
>
> 3) this is const myApps*, inherits QObject; hence should match const
> QObject*
>
> 4) a SIGNAL-macro; matches const char*
>
> Test number two: does your compiler know it is like this?
>
> 2 and 4 are trivial: it already tells you it resolved to const
> char[something]
>
> 1 and 3 are trickier: did you really include all necessary header files that
> declare these classes? I'd guess no, because this error means GCC does not
> know that myThread*& and myApps* are equivalent to QObject*.
I include qobject.h in myapps.h and mythread.h and gcc complains it;
Then i inherits myThread from QObject and QThread and gcc passed;
It's strange.
It seems that QThead not inherits QObject but QT in qt 3.3.6
>
> If the code you quoted really comes from your real code, then I'd venture
> that this line also generated an error:
> myThread *thread=new myThread();
>
> GCC can't possibly know how to instantiate a myThread if it doesn't even
> know it is derived from QThread/QObject.
>
> Something about style: you start class names with lower-case letters. This
> is very confusing, since you really can't see immediately what is a class
> and what is a variable.
>
> Something else about style: try at least to use upper case letters in your
> English language sentences. It shows some respect. I would have skipped
> your mail for that if this had not been such a good opportunity to brag
> about my GCC-knowledge to the rest of the list... ;-)
>
>
> Konrad
>
>
--
[ signature omitted ]