Qt-interest Archive, October 2007
QVariant, Slots and Signals
Pages: Prev | 1 | 2 | Next
Message 1 in thread
Hello.
Is it safe to use QVariant as type for slot/signal parameter? Today I've
discovered in my program that QVariant variable passed to signal (emit
sampleSignal(id, v)) has address 0x0 when arriving in slot. All other types
work perfectly, but QVariant - don't. emit and slot are in the same thread.
Also I've tried to localize that behavior but without success - small code
works perfectly, complex - don't work.
In Qt examples/demos/docs I haven't found any code that uses QVariant in
signals. Maybe something wrong with this type and someone already met with
problem like this.
I'm using Debian GNU/Linux Lenny, Qt4 4.3.1
--
[ signature omitted ]
Message 2 in thread
On 28.10.07 04:25:38, Sergei Stolyarov wrote:
> Is it safe to use QVariant as type for slot/signal parameter?
In general: Yes.
> Today I've
> discovered in my program that QVariant variable passed to signal (emit
> sampleSignal(id, v)) has address 0x0 when arriving in slot.
Whats inside the QVariant, i.e. what type does it contain? Do you have
any messages on the console output? Are you sure the variant has a
proper adressed when the emit is executed?
> All other types work perfectly, but QVariant - don't. emit and slot
> are in the same thread.
In that case an emit bois down to a simple call of the slot at that
place. If you have the receiving object at hand on the emit-line, try
calling its slot directly with the parameters.
> Also I've tried to localize that behavior but without success - small code
> works perfectly, complex - don't work.
Then you stripped your code down too much :) At least you could show us
the declaration of both the signal and the slot.
> In Qt examples/demos/docs I haven't found any code that uses QVariant in
> signals. Maybe something wrong with this type and someone already met with
> problem like this.
No, the only "problems" I've had were simple oversights from me when
using custom data types wrapped in a QVariant. You need to make sure to
use Q_DECLARE_METATYPE() macro and also execute qRegisterMetatype()
somewhere during your apps startup.
Andreas
--
[ signature omitted ]
Message 3 in thread
On Sunday 28 October 2007, Andreas Pakulat wrote:
> On 28.10.07 04:25:38, Sergei Stolyarov wrote:
> > Is it safe to use QVariant as type for slot/signal parameter?
>
> In general: Yes.
>
> > Today I've
> > discovered in my program that QVariant variable passed to signal (emit
> > sampleSignal(id, v)) has address 0x0 when arriving in slot.
>
> Whats inside the QVariant, i.e. what type does it contain? Do you have
> any messages on the console output? Are you sure the variant has a
> proper adressed when the emit is executed?
Any value: empty object QVariant(), copy of existing object - in any case slot
is receiving variable with address 0x0. When I use pointer to QVariant (in
signal/clot declarartion) it works. When I use QString, for example, it
works. No messages in console too.
>
> > All other types work perfectly, but QVariant - don't. emit and slot
> > are in the same thread.
>
> In that case an emit bois down to a simple call of the slot at that
> place. If you have the receiving object at hand on the emit-line, try
> calling its slot directly with the parameters.
>
> > Also I've tried to localize that behavior but without success - small
> > code works perfectly, complex - don't work.
>
> Then you stripped your code down too much :) At least you could show us
> the declaration of both the signal and the slot.
class Client {
...
signals:
void done( int requestId, QVariant );
...
};
class Connector
{
...
public slots:
void loginRequestDone(int, QVariant);
...
}
>
> > In Qt examples/demos/docs I haven't found any code that uses QVariant in
> > signals. Maybe something wrong with this type and someone already met
> > with problem like this.
>
> No, the only "problems" I've had were simple oversights from me when
> using custom data types wrapped in a QVariant. You need to make sure to
> use Q_DECLARE_METATYPE() macro and also execute qRegisterMetatype()
> somewhere during your apps startup.
Thanks, but I don't use custom types inside QVariant. Today I'll try to finish
that simple test to show the error.
--
[ signature omitted ]
Message 4 in thread
On Sunday 28 October 2007, Sergei Stolyarov wrote:
> > > Also I've tried to localize that behavior but without success - small
> > > code works perfectly, complex - don't work.
> >
> > Then you stripped your code down too much :) At least you could show us
> > the declaration of both the signal and the slot.
http://regolit.com/files/qvariant.zip
This is working (i.e. NOT working) test. Just compile, run, click Login button
and application will crash.
Signal that contains invalid QVariant is emitting from file:line
./xmlrpc/client.cpp:305
receiving in file:line
./testproto/t_connector.cpp:46
you may add there something like
qDebug() << &value;
to see that variable "value" has address 0x0
Application uses QXMLRPC library found via qtcentre.org, before I've used my
own XMLRPC library but with the absolutely same result. You may use any
XML-RPC service, in this example I'm using livejournal.com XML-RPC interface.
--
[ signature omitted ]
Message 5 in thread
Hi
,
> http://regolit.com/files/qvariant.zip
It would help if you could strip down this example program.
--
[ signature omitted ]
Message 6 in thread
Hi,
> http://regolit.com/files/qvariant.zip
>
> This is working (i.e. NOT working) test. Just compile, run, click Login button
> and application will crash.
This example does not compile here - inside moc generated code:
moc_t_connector.cpp(70): error: cannot convert to incomplete class "QVariant"
case 0: loginRequestDone((*reinterpret_cast<
int(*)>(_a[1])),(*reinterpret_cast< QVariant(*)>(_a[2]))); break;
I has to include <Qvariant> in t_connector.h to have it compile.
--
[ signature omitted ]
Message 7 in thread
Hi,
> http://regolit.com/files/qvariant.zip
>
> This is working (i.e. NOT working) test. Just compile, run, click Login button
> and application will crash.
You mean the "Connect" button? I can't get the example to crash (on Linux
Fedora 7). It just outputs messages like:
xmlrpc request( 2 ): "LJ.XMLRPC.getchallenge"
"[ [ ] ]"
request "LJ.XMLRPC.getchallenge" finished, id= 2 , isError: false
"{ auth_scheme="c0",
challenge="c0:1193562000:2374:60:deeFWts4fc1du1ubCCoB:98901fd0a836f54a63dd2cafab3582fb",
expire_time=1193564434, server_time=1193564374 }"
XMLRPC Client thread id: 3086702928
Connector thread id: 3086702928
Then it waits forever.
--
[ signature omitted ]
Message 8 in thread
On Sunday 28 October 2007, Dimitri wrote:
> Hi,
>
> > http://regolit.com/files/qvariant.zip
> >
> > This is working (i.e. NOT working) test. Just compile, run, click Login
> > button and application will crash.
>
> You mean the "Connect" button? I can't get the example to crash (on Linux
> Fedora 7). It just outputs messages like:
>
> xmlrpc request( 2 ): "LJ.XMLRPC.getchallenge"
> "[ [ ] ]"
> request "LJ.XMLRPC.getchallenge" finished, id= 2 , isError: false
> "{ auth_scheme="c0",
> challenge="c0:1193562000:2374:60:deeFWts4fc1du1ubCCoB:98901fd0a836f54a63dd2
>cafab3582fb", expire_time=1193564434, server_time=1193564374 }"
> XMLRPC Client thread id: 3086702928
> Connector thread id: 3086702928
>
> Then it waits forever.
What version of Qt you are using? Maybe there is some kind of bug in my
(4.3.1).
On my computer program crashes:
request "LJ.XMLRPC.getchallenge" finished, id= 2 , isError: false
"{ auth_scheme="c0",
challenge="c0:1193565600:2367:60:C5cpyEf1qwiUnbOppGdc:63e4a521df5d4691714ea12a6bf9ed04",
expire_time=1193568027, server_time=1193567967 }"
XMLRPC Client thread id: 3069859520
Connector thread id: 3069859520
Segmentation fault
> This example does not compile here - inside moc generated code:
Also it compiles fine in my environment
--
[ signature omitted ]
Message 9 in thread
Hi,
> What version of Qt you are using? Maybe there is some kind of bug in my
> (4.3.1).
I'm using our internal Qt 4.3 branch, which should be very close to Qt 4.3.2 -
and identical to Qt 4.3 snapshots.
> Also it compiles fine in my environment
OK, it does compile with GCC - but not with Intel C++. Try including
<Qvariant> in t_connector.h nevertheless.
--
[ signature omitted ]
Message 10 in thread
On Sunday 28 October 2007, Dimitri wrote:
> Hi,
>
> > What version of Qt you are using? Maybe there is some kind of bug in my
> > (4.3.1).
>
> I'm using our internal Qt 4.3 branch, which should be very close to Qt
> 4.3.2 - and identical to Qt 4.3 snapshots.
Will try to compile it on different OSes to check but looks that something
wrong with signal passing to slot. If I use less complex class hierarchy then
QVariant is passing normally, but in my case it doesn't. In the earlier
versions (week ago or something like) the same problem occurred but
was "fixed" by placing connect() calls to the different file: when it called
from one file, problem occured, when from another - didn't. But that version
wasn't backed up so I can't provide it :(
> > Also it compiles fine in my environment
>
> OK, it does compile with GCC - but not with Intel C++. Try including
> <Qvariant> in t_connector.h nevertheless.
Ok, thanks.
--
[ signature omitted ]
Message 11 in thread
Hi,
> Will try to compile it on different OSes to check but looks that something
> wrong with signal passing to slot. If I use less complex class hierarchy then
> QVariant is passing normally, but in my case it doesn't. In the earlier
> versions (week ago or something like) the same problem occurred but
> was "fixed" by placing connect() calls to the different file: when it called
> from one file, problem occured, when from another - didn't. But that version
> wasn't backed up so I can't provide it :(
In any case I would like to see a stripped down example. The one you provided
is really much too large.
--
[ signature omitted ]
Message 12 in thread
On Sunday 28 October 2007, Dimitri wrote:
> Hi,
>
> > Will try to compile it on different OSes to check but looks that
> > something wrong with signal passing to slot. If I use less complex class
> > hierarchy then QVariant is passing normally, but in my case it doesn't.
> > In the earlier versions (week ago or something like) the same problem
> > occurred but was "fixed" by placing connect() calls to the different
> > file: when it called from one file, problem occured, when from another -
> > didn't. But that version wasn't backed up so I can't provide it :(
>
> In any case I would like to see a stripped down example. The one you
> provided is really much too large.
Yep, I'm trying.
--
[ signature omitted ]
Message 13 in thread
On Sunday 28 October 2007, Dimitri wrote:
> Hi,
>
> > Will try to compile it on different OSes to check but looks that
> > something wrong with signal passing to slot. If I use less complex class
> > hierarchy then QVariant is passing normally, but in my case it doesn't.
> > In the earlier versions (week ago or something like) the same problem
> > occurred but was "fixed" by placing connect() calls to the different
> > file: when it called from one file, problem occured, when from another -
> > didn't. But that version wasn't backed up so I can't provide it :(
>
> In any case I would like to see a stripped down example. The one you
> provided is really much too large.
Here is a new edition,
http://regolit.com/files/qvariant-2.zip
This is much stripped edition, on my machine it still crashes in file:line
testproto/t_connector.cpp:37
--
[ signature omitted ]
Message 14 in thread
Hi,
> This is much stripped edition, on my machine it still crashes in file:line
> testproto/t_connector.cpp:37
This example can still be simplified. For example it shouldn't need a user
interface. A minimal example should be around 50 lines of code. By the way,
you haven't included <QVariant> in t_connector.h.
Unfortunately, I don't see a crash under Linux. I've even run the program
within Valgrind to detect memory errors, without success.
Therefore the only way for me to help is reviewing the source code. For that I
would need a minimal example.
--
[ signature omitted ]
Message 15 in thread
On Mittwoch, 31. Oktober 2007, Dimitri wrote:
> Hi,
>
> > This is much stripped edition, on my machine it still crashes in
> > file:line testproto/t_connector.cpp:37
>
> This example can still be simplified. For example it shouldn't need a
> user interface. A minimal example should be around 50 lines of code.
> By the way, you haven't included <QVariant> in t_connector.h.
I can reproduce the crash and including qvariant.h fixes the crash
instantly. I also stepped through the code in gdb and saw that in
t_connector::qt_metacall the QVariant in the array is still fine, so
the corruption happens while actually executing the call to
slotRequestFinished.
> Unfortunately, I don't see a crash under Linux. I've even run the
> program within Valgrind to detect memory errors, without success.
I do under Debian with qt-copy from kde's svn. Another way around the
crash is to use a const QVariant& instead of a QVariant as paramter for
signal and slot.
Andreas
--
[ signature omitted ]
Pages: Prev | 1 | 2 | Next