Qt-interest Archive, May 2008
Howto wait for data in QAbstractItemModel::data?
Message 1 in thread
Hi all,
I'm using a class derived from QAbstractItemModel from a source which delivers
data very slow. Usually I'm using an asynchronous approach by first returning
an empty record in QAbstractItemModel::data and later sending a
dataChanged-signal when the right data arrives from the slow source. Thus the
user can scroll very fast thru views like a QTableView and the slow source
does not block the whole application.
The get a synchronous behavior I've just inserted a processEvents()-call in
QAbstractItemModel::data which waits till the requested data arrives. But
this result in a segfault after issuing a lot of messages like this:
QPaintEngine::setSystemClip: Should not be changed while engine is active
QPaintEngine::setSystemClip: Should not be changed while engine is active
QWidgetPrivate::beginSharedPainter: Painter is already active
QPainter::begin: A paint device can only be painted by one painter at a time.
I assume the view calls data() inside a paint event and processEvents()
reissues another paint event to the view. But I need to run processEvents()
because the communication between my app and the server delivering data from
the data source is heavily based on signal/slots and I can't see another way
to wait for data. So I'm having a problem.
Anybody here with a good advice? How can I wait in QAbstractItemModel::data
without blocking the whole application?
Mathias
--
[ signature omitted ]
Message 2 in thread
On 20.05.08 11:24:14, Mathias Waack wrote:
> The get a synchronous behavior I've just inserted a processEvents()-call in
> QAbstractItemModel::data which waits till the requested data arrives. But
> this result in a segfault after issuing a lot of messages like this:
>
> QPaintEngine::setSystemClip: Should not be changed while engine is active
> QPaintEngine::setSystemClip: Should not be changed while engine is active
> QWidgetPrivate::beginSharedPainter: Painter is already active
> QPainter::begin: A paint device can only be painted by one painter at a time.
>
> I assume the view calls data() inside a paint event and processEvents()
Yeap.
> reissues another paint event to the view. But I need to run processEvents()
processEvents() is nothing one should call, unless you know the Qt event
system in full detail and there's no way around it.
> because the communication between my app and the server delivering data from
> the data source is heavily based on signal/slots and I can't see another way
> to wait for data. So I'm having a problem.
The problem is not signals/slots, those don't use the event loop in the
normal case. But the communication itself is probably asynchronous,
which causes the signals to be emitted over time..
> Anybody here with a good advice? How can I wait in QAbstractItemModel::data
> without blocking the whole application?
You can't and you shouldn't. Pre-Fetch the data and only tell the view
about new data once it arrives. Not via dataChanged, but by emitting
rowsInserted as soon as you got another row of data from your server.
When you do this, the model just gets the data from the server and
stores it temporarily until a complete row is there, then it tells the
view via apropriate signals or calls to begin/endInsertRows() that
there's a new row of data available.
Andreas
--
[ signature omitted ]
Message 3 in thread
On Tuesday 20 May 2008, Andreas Pakulat wrote:
> On 20.05.08 11:24:14, Mathias Waack wrote:
> > The get a synchronous behavior I've just inserted a processEvents()-call
> > in QAbstractItemModel::data which waits till the requested data arrives.
> > But this result in a segfault after issuing a lot of messages like this:
> >
> > QPaintEngine::setSystemClip: Should not be changed while engine is active
> > QPaintEngine::setSystemClip: Should not be changed while engine is active
> > QWidgetPrivate::beginSharedPainter: Painter is already active
> > QPainter::begin: A paint device can only be painted by one painter at a
> > time.
> >
> > I assume the view calls data() inside a paint event and processEvents()
>
> Yeap.
>
> > reissues another paint event to the view. But I need to run
> > processEvents()
>
> processEvents() is nothing one should call, unless you know the Qt event
> system in full detail and there's no way around it.
>
> > because the communication between my app and the server delivering data
> > from the data source is heavily based on signal/slots and I can't see
> > another way to wait for data. So I'm having a problem.
>
> The problem is not signals/slots, those don't use the event loop in the
> normal case. But the communication itself is probably asynchronous,
> which causes the signals to be emitted over time..
>
> > Anybody here with a good advice? How can I wait in
> > QAbstractItemModel::data without blocking the whole application?
>
> You can't and you shouldn't. Pre-Fetch the data and only tell the view
> about new data once it arrives. Not via dataChanged, but by emitting
> rowsInserted as soon as you got another row of data from your server.
> When you do this, the model just gets the data from the server and
> stores it temporarily until a complete row is there, then it tells the
> view via apropriate signals or calls to begin/endInsertRows() that
> there's a new row of data available.
Thats what I do. But in addition I would like to have something like
QAbstractSocket::waitForConnected()
for the model. Why shouldn't I? The trolls do it for sockets, so why shouldn't
I do it for a model?
Mathias
--
[ signature omitted ]
Message 4 in thread
On 20.05.08 15:22:13, Mathias Waack wrote:
> On Tuesday 20 May 2008, Andreas Pakulat wrote:
> > On 20.05.08 11:24:14, Mathias Waack wrote:
> > > Anybody here with a good advice? How can I wait in
> > > QAbstractItemModel::data without blocking the whole application?
> >
> > You can't and you shouldn't. Pre-Fetch the data and only tell the view
> > about new data once it arrives. Not via dataChanged, but by emitting
> > rowsInserted as soon as you got another row of data from your server.
> > When you do this, the model just gets the data from the server and
> > stores it temporarily until a complete row is there, then it tells the
> > view via apropriate signals or calls to begin/endInsertRows() that
> > there's a new row of data available.
>
> Thats what I do. But in addition I would like to have something like
>
> QAbstractSocket::waitForConnected()
>
> for the model. Why shouldn't I? The trolls do it for sockets, so why shouldn't
> I do it for a model?
Because thats not how the model/view was designed. If you emit the
signals that tell the view there's a new row, the view expects that you
already have all the data for the row. You shouldn't do very long
calculations in data() as it will block your applications GUI, there's
no way around that.
Andreas
--
[ signature omitted ]
Message 5 in thread
Hi,
Is someone has an idea to control signal/slots connections.
I modify a piece of code that used another event loop and widgets
communication.
this system was able to verify if some object was connected to signal of
other object.
it was not Qt used but similary widgets communication.
The problem I have is that I don't see how to reproduce the test:
if (object is connected)
disconnect this object
so, actually, I call disconnect without knowing if there is connections
and so, see warnings messages about disconnection impossible because
there is nothing to disconnect.
so, I suppose that somewhere there is the info about what is connected
(sender, receiver, signals...) but don't understand how to get this info.
if someone can give me tips, link, idea ?...
thank you in advance.
regards,
Veronique.
--
[ signature omitted ]
Message 6 in thread
Perhaps you should be less specific when disconnecting:
disconnect(myObject, 0, myReceiver, 0);
from: http://doc.trolltech.com/4.3/qobject.html#disconnect
0 may be used as a wildcard, meaning "any signal", "any receiving object", or "any slot in the receiving object", respectively.
Cheers,
Peter
> -----Ursprüngliche Nachricht-----
> Von: Véronique LEFRERE [mailto:veronique.lefrere@xxxxxx]
> Gesendet: Dienstag, 20. Mai 2008 18:13
> An: qt-interest@xxxxxxxxxxxxx
> Betreff: how to have infos about connecitons? Qt434 used
>
> Hi,
>
> Is someone has an idea to control signal/slots connections.
>
> I modify a piece of code that used another event loop and widgets
> communication.
> this system was able to verify if some object was connected
> to signal of
> other object.
> it was not Qt used but similary widgets communication.
>
> The problem I have is that I don't see how to reproduce the test:
> if (object is connected)
> disconnect this object
>
>
> so, actually, I call disconnect without knowing if there is
> connections
> and so, see warnings messages about disconnection impossible because
> there is nothing to disconnect.
> so, I suppose that somewhere there is the info about what is
> connected
> (sender, receiver, signals...) but don't understand how to
> get this info.
>
>
> if someone can give me tips, link, idea ?...
> thank you in advance.
>
> regards,
> Veronique.
--
[ signature omitted ]
Message 7 in thread
QT4 has class QConnectionList which used to keep the list of the connections.
Unfortunatell it is declared in qobject.cpp and is not accessible outside.
So if disconnecting everything does not work for you and you need disconnect specific slot you either will have to keep your own list of connections or always disconnect and reconnect as you do.
I am not sure why trolltech chosen do not provide query interface for connections. It seems it is pretty easy to make it user accessible and functions are already implemented but are hidden in the private part.
There are situation when these functions are usefull and in the most cases it would work faster than disconnecting and connecting cause you can't check was it connected or not.
Alex Malyushytsky
Research Engineer - Weidlinger Associates Inc.
-----Original Message-----
From: Peter Prade [mailto:prade@xxxxxxxxxxx]
Sent: Tuesday, May 20, 2008 9:50 AM
To: qt-interest@xxxxxxxxxxxxx
Subject: AW: how to have infos about connecitons? Qt434 used
Perhaps you should be less specific when disconnecting:
disconnect(myObject, 0, myReceiver, 0);
from: http://doc.trolltech.com/4.3/qobject.html#disconnect
0 may be used as a wildcard, meaning "any signal", "any receiving object", or "any slot in the receiving object", respectively.
Cheers,
Peter
> -----Ursprüngliche Nachricht-----
> Von: Véronique LEFRERE [mailto:veronique.lefrere@xxxxxx]
> Gesendet: Dienstag, 20. Mai 2008 18:13
> An: qt-interest@xxxxxxxxxxxxx
> Betreff: how to have infos about connecitons? Qt434 used
>
> Hi,
>
> Is someone has an idea to control signal/slots connections.
>
> I modify a piece of code that used another event loop and widgets
> communication.
> this system was able to verify if some object was connected
> to signal of
> other object.
> it was not Qt used but similary widgets communication.
>
> The problem I have is that I don't see how to reproduce the test:
> if (object is connected)
> disconnect this object
>
>
> so, actually, I call disconnect without knowing if there is
> connections
> and so, see warnings messages about disconnection impossible because
> there is nothing to disconnect.
> so, I suppose that somewhere there is the info about what is
> connected
> (sender, receiver, signals...) but don't understand how to
> get this info.
>
>
> if someone can give me tips, link, idea ?...
> thank you in advance.
>
> regards,
> Veronique.
--
[ signature omitted ]
Message 8 in thread
Peter,
Sorry to replying to you and not to the list.
Alex
-----Original Message-----
From: Malyushytsky, Alex [mailto:alex@xxxxxxx]
Sent: Tuesday, May 20, 2008 12:24 PM
To: Peter Prade; qt-interest@xxxxxxxxxxxxx
Subject: RE: how to have infos about connecitons? Qt434 used
QT4 has class QConnectionList which used to keep the list of the connections.
Unfortunatell it is declared in qobject.cpp and is not accessible outside.
So if disconnecting everything does not work for you and you need disconnect specific slot you either will have to keep your own list of connections or always disconnect and reconnect as you do.
I am not sure why trolltech chosen do not provide query interface for connections. It seems it is pretty easy to make it user accessible and functions are already implemented but are hidden in the private part.
There are situation when these functions are usefull and in the most cases it would work faster than disconnecting and connecting cause you can't check was it connected or not.
Alex Malyushytsky
Research Engineer - Weidlinger Associates Inc.
-----Original Message-----
From: Peter Prade [mailto:prade@xxxxxxxxxxx]
Sent: Tuesday, May 20, 2008 9:50 AM
To: qt-interest@xxxxxxxxxxxxx
Subject: AW: how to have infos about connecitons? Qt434 used
Perhaps you should be less specific when disconnecting:
disconnect(myObject, 0, myReceiver, 0);
from: http://doc.trolltech.com/4.3/qobject.html#disconnect
0 may be used as a wildcard, meaning "any signal", "any receiving object", or "any slot in the receiving object", respectively.
Cheers,
Peter
> -----Ursprüngliche Nachricht-----
> Von: Véronique LEFRERE [mailto:veronique.lefrere@xxxxxx]
> Gesendet: Dienstag, 20. Mai 2008 18:13
> An: qt-interest@xxxxxxxxxxxxx
> Betreff: how to have infos about connecitons? Qt434 used
>
> Hi,
>
> Is someone has an idea to control signal/slots connections.
>
> I modify a piece of code that used another event loop and widgets
> communication.
> this system was able to verify if some object was connected
> to signal of
> other object.
> it was not Qt used but similary widgets communication.
>
> The problem I have is that I don't see how to reproduce the test:
> if (object is connected)
> disconnect this object
>
>
> so, actually, I call disconnect without knowing if there is
> connections
> and so, see warnings messages about disconnection impossible because
> there is nothing to disconnect.
> so, I suppose that somewhere there is the info about what is
> connected
> (sender, receiver, signals...) but don't understand how to
> get this info.
>
>
> if someone can give me tips, link, idea ?...
> thank you in advance.
>
> regards,
> Veronique.
--
[ signature omitted ]
Message 9 in thread
Malyushytsky, Alex wrote:
> QT4 has class QConnectionList which used to keep the list of
> the connections.
>
> Unfortunatell it is declared in qobject.cpp and is not
> accessible outside.
>
> So if disconnecting everything does not work for you and you
> need disconnect specific slot you either will have to keep
> your own list of connections or always disconnect and
> reconnect as you do.
>
> I am not sure why trolltech chosen do not provide query
> interface for connections. It seems it is pretty easy to make
> it user accessible and functions are already implemented but
> are hidden in the private part.
>
> There are situation when these functions are usefull and in
> the most cases it would work faster than disconnecting and
> connecting cause you can't check was it connected or not.
i think it's a design decision: hide stuff away from the API if it is
not really needed.
Also these functions could be abused, so by hiding it away, they help us
to write good code (that doesn't rely on the ugly internals ;)
TT seems to be reluctant to tell anything about the internals, even if
it's only the number of connected receivers of a signal:
from the docs of "int QObject::receivers()"
http://doc.trolltech.com/4.3/qobject.html#receivers
Warning: This function violates the object-oriented principle of
modularity.
However, it might be useful when you need to perform expensive
initialization only if something is connected to a signal.
Cheers,
Peter
--
[ signature omitted ]
Message 10 in thread
good idea, I'll try this wildcard possibility if possible for my case.
thank you,
have a nice day.
veronique.
Quoting Peter Prade <prade@xxxxxxxxxxx>:
> Perhaps you should be less specific when disconnecting:
>
> disconnect(myObject, 0, myReceiver, 0);
>
> from: http://doc.trolltech.com/4.3/qobject.html#disconnect
>
> 0 may be used as a wildcard, meaning "any signal", "any receiving
> object", or "any slot in the receiving object", respectively.
>
> Cheers,
> Peter
>
>> -----Ursprüngliche Nachricht-----
>> Von: Véronique LEFRERE [mailto:veronique.lefrere@xxxxxx]
>> Gesendet: Dienstag, 20. Mai 2008 18:13
>> An: qt-interest@xxxxxxxxxxxxx
>> Betreff: how to have infos about connecitons? Qt434 used
>>
>> Hi,
>>
>> Is someone has an idea to control signal/slots connections.
>>
>> I modify a piece of code that used another event loop and widgets
>> communication.
>> this system was able to verify if some object was connected
>> to signal of
>> other object.
>> it was not Qt used but similary widgets communication.
>>
>> The problem I have is that I don't see how to reproduce the test:
>> if (object is connected)
>> disconnect this object
>>
>>
>> so, actually, I call disconnect without knowing if there is
>> connections
>> and so, see warnings messages about disconnection impossible because
>> there is nothing to disconnect.
>> so, I suppose that somewhere there is the info about what is
>> connected
>> (sender, receiver, signals...) but don't understand how to
>> get this info.
>>
>>
>> if someone can give me tips, link, idea ?...
>> thank you in advance.
>>
>> regards,
>> Veronique.
>
> --
> 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/
>
>
----------------------------------------------------------------
Ce message electronique et tous les fichiers joints qu'il contient
(ci-apres "le message") sont confidentiels et destines exclusivement a
l'usage des destinataires indiques ou des personnes dument habilitees
a les recevoir a leur place.
Si vous recevez ce message par erreur, merci de bien vouloir le
detruire et d'en avertir l'emetteur.
Toute utilisation de ce message non conforme a sa destination, toute
diffusion ou toute publication totale ou partielle est interdite sauf
autorisation expresse de l'emetteur.
Les idees et opinions exprimees dans ce message sont celles de son
auteur et ne representent pas necessairement celles de CS
Communication & Systemes ou de ses filiales.
Malgre toutes les dispositions prises par CS Communication & Systemes
et ses filiales pour minimiser les risques de virus, les fichiers
joints a ce message peuvent contenir des virus qui pourraient
endommager votre systeme informatique. Il vous appartient d'effectuer
vos propres controles anti-virus avant d'ouvrir les fichiers joints.
CS Communication & Systemes et ses filiales declinent toute
responsabilite pour toute perte ou dommage resultant de l'utilisation
de ce message et/ou des fichiers joints.
This e-mail and any file attached hereto (hereinafter 'the e-mail')
are confidential and intended solely for the use of the adressees
indicated below or the persons duly entitled to receive them in their
place.
If you receive this e-mail in error, please delete it and notify the sender.
Any use of this e-mail not in accordance with its purpose, any
dissemination or disclosure, either whole or partial, is prohibited,
unless formally approved by the sender.
The ideas or opinions expressed in this e-mail are solely those of its
author and do not necessarily represent those of CS Communication &
Systeme or its affiliates.
Despite all the measures taken by CS Communication & Systeme and its
affiliates in order to minimize the risks of virus, the files attached
to this e-mail may contain virus which could damage your information
system. You are responsible for processing your own anti-virus
checking before opening any file attached hereto. Neither CS
Communication & Systemes, nor its affiliates, shall be held liable for
any loss or damage due to the use of this e-mail or any file attached
hereto.
--
[ signature omitted ]