Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-interest Archive, February 2008
Pass C string over signal


Message 1 in thread

Hi,

How can I pass C string char * over signal? I tried, it did not work.

Thanks.

Jim

--
 [ signature omitted ] 

Message 2 in thread

> How can I pass C string char * over signal? I tried, it did not work.

Should work for DirectConnections out-of-the-box.

If you are using QueuedConnections you have to encapsulate the char * into 
an object type which is registered with QMetaType (or can be registered 
with it http://doc.trolltech.com/4.2/qmetatype.html#qRegisterMetaType) 
i.e. a QString or you have to use a void * which is a known type to 
QMetaType...

Regards,
Malte

--
 [ signature omitted ] 

Message 3 in thread

There are probably more elegant methods, but here's a quick and dirty
method that works.
char errorBuffer[];
QCString tempBuffer;
QString myErrorBuffer;

tempBuffer = errorBuffer;
myErrorBuffer = tempBuffer;

The char[] is now a QString with all of the ease of use of a QString.
This is the method I use to display error messages from libpcap.
hth,
Jeffrey

On Tue, 2008-02-05 at 12:12 +0100, Malte Witt wrote:
> > How can I pass C string char * over signal? I tried, it did not work.
> 
> Should work for DirectConnections out-of-the-box.
> 
> If you are using QueuedConnections you have to encapsulate the char * into 
> an object type which is registered with QMetaType (or can be registered 
> with it http://doc.trolltech.com/4.2/qmetatype.html#qRegisterMetaType) 
> i.e. a QString or you have to use a void * which is a known type to 
> QMetaType...
> 
> Regards,
> Malte
> 
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
> 

-- 
 [ signature omitted ] 

Message 4 in thread

Mooser wrote: 
> There are probably more elegant methods, but here's a quick and dirty
> method that works.
> char errorBuffer[];
> QCString tempBuffer;
> QString myErrorBuffer;
> 
> tempBuffer = errorBuffer;
> myErrorBuffer = tempBuffer;

QCString? what version of Qt are you using?

to convert a char* to a QString, you can use QString::fromAscii()
http://doc.trolltech.com/4.3/qstring.html#fromAscii
(or one of the other fromXyz() functions)

Jim wrote: 
>>> How can I pass C string char * over signal? I tried, it did not
work.

you probably have the problem that the (char *) pointer is no longer
valid (i.e. the buffer it points to has been freed already) when you're
trying to use it in the slot.
There are several scenarios where this can happen. in each case it is
probably easiest if you convert it to a QString.
If this doesn't help you, show us some code!

Cheers,
Peter

--
 [ signature omitted ] 

Message 5 in thread

Using 3.3.5. But, I knew if I posted what I did I would learn new and
better ways. Overlooked fromAscii().
Thx,
Jeffrey

On Tue, 2008-02-05 at 14:34 +0100, Peter Prade wrote:
> Mooser wrote: 
> > There are probably more elegant methods, but here's a quick and dirty
> > method that works.
> > char errorBuffer[];
> > QCString tempBuffer;
> > QString myErrorBuffer;
> > 
> > tempBuffer = errorBuffer;
> > myErrorBuffer = tempBuffer;
> 
> QCString? what version of Qt are you using?
> 
> to convert a char* to a QString, you can use QString::fromAscii()
> http://doc.trolltech.com/4.3/qstring.html#fromAscii
> (or one of the other fromXyz() functions)
> 
> Jim wrote: 
> >>> How can I pass C string char * over signal? I tried, it did not
> work.
> 
> you probably have the problem that the (char *) pointer is no longer
> valid (i.e. the buffer it points to has been freed already) when you're
> trying to use it in the slot.
> There are several scenarios where this can happen. in each case it is
> probably easiest if you convert it to a QString.
> If this doesn't help you, show us some code!
> 
> Cheers,
> Peter
> 
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
> 
> 
-- 
 [ signature omitted ] 

Message 6 in thread

On 2/5/08, Malte Witt <malte.witt@xxxxxxxxxxxxx> wrote:
> > How can I pass C string char * over signal? I tried, it did not work.
>
> Should work for DirectConnections out-of-the-box.
>
> If you are using QueuedConnections you have to encapsulate the char * into
> an object type which is registered with QMetaType (or can be registered
> with it http://doc.trolltech.com/4.2/qmetatype.html#qRegisterMetaType)
> i.e. a QString or you have to use a void * which is a known type to
> QMetaType...

I've changed all signal in QString, using following connect:

connect(&mSerialPort, SIGNAL(Read(QString &)), &mPanel, SLOT(Read(QString &)));

And, it produced an error as well:

QObject::connect: Cannot queue arguments of type 'QString&'
(Make sure 'QString&' is registered using qRegisterMetaType().)

Or it can only be passed by a value not reference "QString &"?

Thank you.

Kind Regards,

Jim

--
 [ signature omitted ] 

Message 7 in thread

hce wrote:
>Or it can only be passed by a value not reference "QString &"?

const QString &

-- 
 [ signature omitted ] 

Attachment: signature.asc
Description: This is a digitally signed message part.


Message 8 in thread

On Feb 5, 2008 11:49 AM, hce <webmail.hce@xxxxxxxxx> wrote:
> Hi,
>
> How can I pass C string char * over signal? I tried, it did not work.

How did you try and how did it not work?

-- 
 [ signature omitted ]