wxThread Help!!!!

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
chakkaradeepcc
Earned some good credits
Earned some good credits
Posts: 116
Joined: Mon Nov 01, 2004 6:31 pm
Location: India
Contact:

wxThread Help!!!!

Post by chakkaradeepcc »

Hi all,

i went thru the Thread Sample which is provided along with the wxWidgets Sample Directory................it was gud...i was able to understand every line of it..but when i tried implementing wxThread in my Program , it is throwing Error , the error is ,
interface.cpp: At global scope:
interface.cpp:623: error: syntax error before `{' token
interface.cpp:628: error: virtual outside class declaration
interface.cpp:629: error: syntax error before `}' token
interface.cpp:631: error: invalid use of undefined type `class MyThread'
interface.cpp:622: error: forward declaration of `class MyThread'
interface.cpp: In constructor `MyThread::MyThread()':
interface.cpp:631: error: syntax error before `:' token
interface.cpp:633: error: `Create' undeclared (first use this function)
interface.cpp:633: error: (Each undeclared identifier is reported only once for
each function it appears in.)
interface.cpp: At global scope:
interface.cpp:637: error: invalid use of undefined type `class MyThread'
interface.cpp:622: error: forward declaration of `class MyThread'
interface.cpp: In member function `void* MyThread::Entry()':
interface.cpp:639: warning: no return statement in function returning non-void
interface.cpp: In member function `void
I have just declared and defind a Thread class as follows,

Code: Select all


...............my code.................
.......................

void Interface::OnTreectrlItemActivated( wxTreeEvent& event )
{
    /* double click on the tree item */
    //wxMessageBox(::wxGetHostName(),"HostName",0,this);
    wxTreeItemId tree_sel=event.GetItem();
    StartTransmission(0,tree_sel,"");
}

class MyThread : public wxThread
{
public:
    MyThread();

    // thread execution starts here
    virtual void *Entry();
};

MyThread::MyThread() : : wxThread()
{
	Create();
}

void *MyThread::Entry()
{

}

void Interface::OnTETreectrlItemActivated( wxTreeEvent& event )
{
    /* double click on the tree item */
    wxTreeItemId tree_sel=event.GetItem()
..................................my code..............
.................
how to create a thread in our program....i dnt know whats the error..............i would happy if anyone can give me a Thread Sample other than wxWidgets Sample.

with regards,
C.C.Chakkaradeep
cg
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 201
Joined: Sun Aug 29, 2004 12:33 am
Location: Canada
Contact:

Post by cg »

Add:

return 0;

To your Entry method

:D

HTH
CG
chakkaradeepcc
Earned some good credits
Earned some good credits
Posts: 116
Joined: Mon Nov 01, 2004 6:31 pm
Location: India
Contact:

Post by chakkaradeepcc »

Hi cg,

thanks for ur reply..........but thats not even an error...........am re-writing it again......

NOTE: I have included "wx/thread.h"

ERROR

interface.cpp:623: error: syntax error before `{' token
interface.cpp:628: error: virtual outside class declaration
interface.cpp:629: error: syntax error before `}' token
interface.cpp:631: error: invalid use of undefined type `class MyThread'
interface.cpp:622: error: forward declaration of `class MyThread'
interface.cpp: In constructor `MyThread::MyThread()':
interface.cpp:631: error: class `MyThread' does not have any field named `
wxThread'
interface.cpp: At global scope:
interface.cpp:637: error: invalid use of undefined type `class MyThread'
interface.cpp:622: error: forward declaration of `class MyThread'
And Here is my Code....i even added "return 0".......

CODE

622:class MyThread : public wxThread
623:{
624:public:
625: MyThread();
626:
627: // thread execution starts here
628: virtual void *Entry();
629:};
630:
631:MyThread::MyThread() : wxThread()
632:{
633:
634:}
635:
636:void *MyThread::Entry()
637:{
638: return 0;
639:}
I would be happy if theres help..............

with regards,
C.C.Chakkaradeep
cg
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 201
Joined: Sun Aug 29, 2004 12:33 am
Location: Canada
Contact:

Post by cg »

You code snip from your first post has this declaration:

MyThread::MyThread() : : wxThread()
{
Create();
}


there are two ": :" in there. That looks like what the error is complaining about.

or remove the "()" in wxThread()

HTH

CG
chakkaradeepcc
Earned some good credits
Earned some good credits
Posts: 116
Joined: Mon Nov 01, 2004 6:31 pm
Location: India
Contact:

Post by chakkaradeepcc »

Hi cg,

oops...we should be careful while writing to Forums!....sorry cg that "::" was my mistake...

i think i have found the mistake but dnt know how to correct it!....i added these lines at the top to check..

#if !wxUSE_THREADS
#error "This sample requires thread support!"
#endif // wxUSE_THREADS
and while compiling it gave me

This sample requires thread support!"

am working with the VLC Media Player Code.....

I tried a small thread sample in KDevelop and it worked ...........it didnt throw any kinda errors like what i got............

is there anything that i have to do to enable thread support in wxWidgets??

with regards,
C.C.Chakkaradeep
geon
I live to help wx-kind
I live to help wx-kind
Posts: 189
Joined: Tue Sep 07, 2004 4:10 pm
Location: Sweden, Uppsala

Post by geon »

You need to include the threading header, wx/thread.h
chakkaradeepcc
Earned some good credits
Earned some good credits
Posts: 116
Joined: Mon Nov 01, 2004 6:31 pm
Location: India
Contact:

Post by chakkaradeepcc »

Hi,

Am sorry to inform ............i have added all the necessary headers and i had given as a NOTE in my previous posts!.............pls am really n need of help and all the basic things like including the header,inheriting from wxThread have been done...............pls do check out the errors in my post, i have clearly copied the errors which the compiler threw....................

with regards,
C.C.Chakkaradeep
cg
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 201
Joined: Sun Aug 29, 2004 12:33 am
Location: Canada
Contact:

Post by cg »

You can email me your class and I'll look at it today. cgarrett at degarrah.com

CG
geon
I live to help wx-kind
I live to help wx-kind
Posts: 189
Joined: Tue Sep 07, 2004 4:10 pm
Location: Sweden, Uppsala

Post by geon »

Can you compile the source of the thread sample?
chakkaradeepcc
Earned some good credits
Earned some good credits
Posts: 116
Joined: Mon Nov 01, 2004 6:31 pm
Location: India
Contact:

Post by chakkaradeepcc »

Hi geon,

Yes it is working..................i have done no change in the example.

with regards,
C.C.Chakkaradeep
chakkaradeepcc
Earned some good credits
Earned some good credits
Posts: 116
Joined: Mon Nov 01, 2004 6:31 pm
Location: India
Contact:

Post by chakkaradeepcc »

Hi all,

i found out why am getting this ERROR!.........am using VLC Source code and compiling VLC using i586-mingw32msvc-gcc and only this compiler is throwing error that Thre is no Thread Support.........i even tried using Normal "pthread_t" POSIX Programing...it didnt work..........

if someone could tell me how to enable Threading support using the above compiler when coimpiling wxWidgets programs, it would be really helpful......

with regards,
C.C.Chakkaradeep
chakkaradeepcc
Earned some good credits
Earned some good credits
Posts: 116
Joined: Mon Nov 01, 2004 6:31 pm
Location: India
Contact:

Post by chakkaradeepcc »

Hi all,

I made threads to work but NOT WITH wxThread but using _beginthread() functions........mingw compiler uses the above _beginthread function for Threads.......my code got compiled but why is it wxThread not getting compiled........

this sounds to be really different one.........now am continuing my work using _beginthread .... but why is not working with wxWidgtes?..

with regards,
C.C.Chakkaradeep
cg
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 201
Joined: Sun Aug 29, 2004 12:33 am
Location: Canada
Contact:

Post by cg »

I have thread working on four platforms with gcc. On windows you need to pass -mthread flag to gcc.

HTH

CG
chakkaradeepcc
Earned some good credits
Earned some good credits
Posts: 116
Joined: Mon Nov 01, 2004 6:31 pm
Location: India
Contact:

Post by chakkaradeepcc »

Hi cg,

am using i586-mingw32msvc-gcc compiler in Linux Platform and not in Windows Platform.....even then i tried using the -mthread option and the compiler threw "unknown command"!

:-(

with regards,
C.C.Chakkaradeep
cg
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 201
Joined: Sun Aug 29, 2004 12:33 am
Location: Canada
Contact:

Post by cg »

Are you are crosscompiling? If so I would try building this on windows to eliminate the crosscompiler issues as a problem. I would not be suprised if this was causing confusion. If it works then you know your code is ok.

BTW:

on Windows -mthread
on Linux -pthread

HTH

CG
Post Reply