wxMessageQueue for Inter-thread communication Topic is solved

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
Marcus Frenkel
Experienced Solver
Experienced Solver
Posts: 79
Joined: Thu Sep 25, 2008 12:14 am

wxMessageQueue for Inter-thread communication

Post by Marcus Frenkel »

Hi,

I tried the new class wxMessageQueue for inter thread communication that will be available in the next wxWidgets release. Since it is a template it can be used to send arbitrary user data. I tried it with std::string and it works fine, however it doesn't work with std::string array.

I wonder if I do something wrong or it can be used with arrays.

Basically, the message type is std::queue<T>.

I have defined it like this:

Code: Select all

typedef string myStr[4];
wxMessageQueue<myStr[4]> MyQueue;
Then to post message I use:

Code: Select all

string msg[4]={str1,str2,str3,str4};
MyQueue.Post( msg);
On compilation in MS Visual Studio 2008, I don't get any error for the definition, but I get error for using the functions Post and Receive with string array as parameter. The error is below:

Code: Select all

1) : error C2664: 'wxMessageQueue<T>::Post' : cannot convert parameter 1 from 'std::string [4]' to 'const std::basic_string<_Elem,_Traits,_Ax> (&)[4]'
1>        with
1>        [
1>            T=myStr [4]
1>        ]
1>        and
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>,
1>            _Ax=std::allocator<char>
1>        ]
1>        Reason: cannot convert from 'std::string [4]' to 'const std::basic_string<_Elem,_Traits,_Ax> [4]'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>,
1>            _Ax=std::allocator<char>
1>        ]
1>        There is no context in which this conversion is possible
The class can be seen on this link: http://svn.wxwidgets.org/viewvc/wx/wxWi ... iew=markup

TIA, Marcus
Frank
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 211
Joined: Sat Jan 01, 2005 6:19 pm

Post by Frank »

you could use std::array or std::vector instead of a naked array.

If you must use a POD-Array, try wxMessageQueue<std::string*> instead.
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

I don't get this part :

Code: Select all

typedef string myStr[4];
wxMessageQueue<myStr[4]> MyQueue;
Unless I'm doing something weird in my head, I understand that this defines mStr to be a string[4]. When you then pass myStr[4] to the template, wouldn't that mean a string[4][4] ? Then when you pass a string[4] it would fail since you declared the template to expect a string[4][4].
"Keyboard not detected. Press F1 to continue"
-- Windows
Marcus Frenkel
Experienced Solver
Experienced Solver
Posts: 79
Joined: Thu Sep 25, 2008 12:14 am

Post by Marcus Frenkel »

Frank wrote:you could use std::array or std::vector instead of a naked array.

If you must use a POD-Array, try wxMessageQueue<std::string*> instead.
I wanted to go with std::array but it's header is not included in VC++ 2008. I tried to go with simple arrays to avoid the noticeable overhead of using vectors.
Auria wrote: Unless I'm doing something weird in my head, I understand that this defines mStr to be a string[4]. When you then pass myStr[4] to the template, wouldn't that mean a string[4][4] ? Then when you pass a string[4] it would fail since you declared the template to expect a string[4][4].
The way I declared surely doesn't work, but cannot find the right way to do it with naked arrays, it seems there is no way.

Marcus
Post Reply