Hi,
How can I create a Class inherits from two QObject subclasses in Qt 4.3 ?
Eg:
Qt Code:
{ ....... }To copy to clipboard, switch view to plain text mode
Please help me.
Hi,
How can I create a Class inherits from two QObject subclasses in Qt 4.3 ?
Eg:
Qt Code:
{ ....... }To copy to clipboard, switch view to plain text mode
Please help me.
Last edited by jpn; 28th December 2007 at 12:45. Reason: missing [code] tags
It is not possible to inherit from 2 QObject classes. Instead inherit only the first one and make your class to be a wrapper around QThread - it doesn't have that many methods anyway. Create a QThread member and expose its API through your class.
EDIT: look at this... eclipse even tells you you can't inherit from two QObject's:
Last edited by marcel; 28th December 2007 at 12:25.
Hi,
I am not very clear with your answer. Can you please give an sample code for it ?
Hi,
How can I solve this problem?
Please help me
Qt Code:
class MyClass : public Class1 { Q_OBJECT protected: MyThread *mThread; public: ~MyClass(); //expose QThread API void start() { mThread->start(); } }To copy to clipboard, switch view to plain text mode
Here MyThread is a QThread subclass.
sabeesh (28th December 2007)
Hi,
When I try this, at the time of running the program, Qt display an error like this
Please help me to solve this problem.First-chance exception at 0x67015e8a (QtCored4.dll) in Test.exe: 0xC0000005: Access violation reading location 0xcdcdcdd1.
Unhandled exception at 0x67015e8a (QtCored4.dll) in Test.exe: 0xC0000005: Access violation reading location 0xcdcdcdd1.
Last edited by jpn; 31st December 2007 at 08:19. Reason: missing [quote] tags
You're dereferencing an uninitialized pointer. Do you have something like
anywhere in your code?Qt Code:
mThread = new MyThread(this);To copy to clipboard, switch view to plain text mode
J-P Nurmi
Hi
My code is like this
Qt Code:
{ protected: QThread *mThread; ........ public: void start() { mThread->start(); } virtual void run(); }To copy to clipboard, switch view to plain text mode
and in my .cpp file the code is like this
Qt Code:
void CTest::StartCapture (int DeviceNum ){ capture = cvCaptureFromCAM( DeviceNum ); if( !capture ) { fprintf( stderr, "ERROR: capture is NULL \n" ); getchar(); } mThread->start(); } void CWebCamViewer::run() { while( true ) { // Get one frame qApp->processEvents(); ImgFrame = cvQueryFrame( capture ); if( !ImgFrame ) { fprintf( stderr, "ERROR: frame is null...\n" ); getchar(); break; } ReturnImg = IplImageToQImage(ImgFrame); hflip = hflip.scaled(320,240, Qt::IgnoreAspectRatio, Qt::FastTransformation); } }To copy to clipboard, switch view to plain text mode
Please help me to solve that problum.
Last edited by jpn; 31st December 2007 at 09:01. Reason: PS. the closing tag is [/code] not [\code]
Could you answer my question?
J-P Nurmi
Hi,
No, I didn't give a line like this
in my programQt Code:
mThread = new MyThread(this);To copy to clipboard, switch view to plain text mode
So most likely mThread is an uninitialized pointer which points to 0xcdcdcdd1. Don't you think you should have
somewhere?Qt Code:
To copy to clipboard, switch view to plain text mode
J-P Nurmi
Hi
When I give the command in my constructor
Qt Code:
To copy to clipboard, switch view to plain text mode
then Qt return an error like this
.\Test.cpp(70) : error C2259: 'QThread' : cannot instantiate abstract class
due to following members:
'void QThread::run(void)' : is abstract
c:\qt\4.3.0\include\qtcore\qthread.h(87) : see declaration of 'QThread::run'
Last edited by jpn; 31st December 2007 at 09:43. Reason: missing [code] tags
Ahh, indeed. QThread will be non-abstract in Qt 4.4 but until that you will have to implement QThread::run().
J-P Nurmi
Hi,
In my code I had implement the run(). Please see the code , which one i previous declare.
in .h file
and in .cpp file
Qt Code:
void CTest::run() { ..... ..... }To copy to clipboard, switch view to plain text mode
is it correct?
A friendly advise would be to learn C++ before trying to use a comprehensive toolkit written in C++. Using Qt sure requires some knowledge of C++.
What you have shown above declares a method "virtual void run()" in a class which has QThread pointer as a member. That's not at all same than implementing QThread::run().
Notice the difference between:
andQt Code:
{ protected: virtual void run() { ... } QThread* mThread; };To copy to clipboard, switch view to plain text mode
Qt Code:
{ protected: virtual void run() { ... } }; { protected: MyThread* mThread; };To copy to clipboard, switch view to plain text mode
J-P Nurmi
sabeesh (1st January 2008)
Hi,
Its my mistake. Sorry.
I create a class like this
Qt Code:
{ protected: virtual void run(){ while(true){ qDebug()<<"Run"; } } };To copy to clipboard, switch view to plain text mode
and in .h file
and give the command in my constructor like this
Qt Code:
To copy to clipboard, switch view to plain text mode
but the error is like this
Qt Code:
.\Test.cpp(70) : error C2259: 'QThread' : cannot instantiate abstract class due to following members: 'void QThread::run(void)' : is abstract c:\qt\4.3.0\include\qtcore\qthread.h(87) : see declaration of 'QThread::run'To copy to clipboard, switch view to plain text mode
Please help me
QThread is abstract. You must instantiate your QThread subclass:
Qt Code:
mThread = new MyThread(this);To copy to clipboard, switch view to plain text mode
sabeesh (1st January 2008)
Hi,
Ohhhh, It's my mistake. Sorry.
Thankyou for your help
Bookmarks