Qt-interest Archive, March 2002
qt multithreaded
Message 1 in thread
Dear all,
I have a ( quite small abt 4100 lines ) application for which I am
concidering a multithreaded approach. One of the options for this
application is to do a search in its data files, which can be of any
number, thus the search may take several seconds( GUI locks naturally) .
So the obvious thing is to make a QThread inherited class that does the
job of searching. For now the application is not multithreaded, but
single. I use signals and slots for communication between objects that
do the search, also non-GUI objects. Therefore a few questions arise:
Using signals and slots between threads, is that a save way to do it?
For each signal emitted ( from the searcher class in this case ) should
I use qApp->lock / unlock? ( as for now I am updating another object by
sending it signals from the searcher object , which would be in another
thread).
Is the qApp->lock/unlock a semaphore that also protects QObject
inherited objects, which in my case may be also non-GUI objects?
Anything else I should concider before going multithreaded?
Thank's for your time,
/G
--
[ signature omitted ]
Message 2 in thread
Qt signal is not designed for intercommunication between
threads/process. In other words, Qt signal is actually not
a signal, it is only a fuction call.
Keyword 'emit' is defined as empty, so "emit someSignal();"
you wrote is just same as "someSignal();". The moc appends
"someSignal()" implementation in *.moc.cpp file. In that
code, "activate_signal("someSignal()");" is called, and
connecting slots (their pointers are stored in a dictionary
hashed by string) are called sequencially.
So, in your case, a thread emitted a signal goes to a slot
method which you expected is executed in another thread.
For intercommunication between threads, other solutions
like a condition variable, a mutex or a FIFO buffer are
needed.
Naoyuki
On 2002 March 19 Tuesday 15:50, Greger Haga wrote:
> Dear all,
> I have a ( quite small abt 4100 lines ) application for
> which I am concidering a multithreaded approach. One of
> the options for this application is to do a search in its
> data files, which can be of any number, thus the search
> may take several seconds( GUI locks naturally) . So the
> obvious thing is to make a QThread inherited class that
> does the job of searching. For now the application is not
> multithreaded, but single. I use signals and slots for
> communication between objects that do the search, also
> non-GUI objects. Therefore a few questions arise:
>
> Using signals and slots between threads, is that a save
> way to do it? For each signal emitted ( from the searcher
> class in this case ) should I use qApp->lock / unlock? (
> as for now I am updating another object by sending it
> signals from the searcher object , which would be in
> another thread).
> Is the qApp->lock/unlock a semaphore that also protects
> QObject inherited objects, which in my case may be also
> non-GUI objects?
>
> Anything else I should concider before going
> multithreaded? Thank's for your time,
> /G
Message 3 in thread
Hello all,
How to decalre and use global variables..............................
--
[ signature omitted ]
Message 4 in thread
A.BalaSaraswathi wrote:
> Hello all,
>
>
> How to decalre and use global variables..............................
>
You don't :) this would break the OOP paradigm.
You can specify the variables you use in one class file only
in you header file (for own classes) or in Designer in the
Object Explorer / Source View under Class Variables.
If you need access to them from other classes either declare them
public or (much better) create access functions for them (aka setVar/getVar)
Regards,
Reinhard
Message 5 in thread
Hello, A.BalaSaraswathi:
Does "global variables" mean "global instances such as
cout, cerr defined in <iostream>" ?
On 2002 March 19 Tuesday 23:36, Reinhard Katzmann wrote:
> A.BalaSaraswathi wrote:
> > Hello all,
> >
> >
> > How to decalre and use global
> > variables..............................
>
> You don't :) this would break the OOP paradigm.
> You can specify the variables you use in one class file
> only in you header file (for own classes) or in Designer
> in the Object Explorer / Source View under Class
> Variables.
>
> If you need access to them from other classes either
> declare them public or (much better) create access
> functions for them (aka setVar/getVar)
>
> Regards,
>
> Reinhard
Message 6 in thread
Well, I want to say it is a kind of 'Singleton design
pattern' problem., who creates it, how long its longevity
and so on... sorry.
Naoyuki
On 2002 March 20 Wednesday 00:17, I wrote:
> Hello, A.BalaSaraswathi:
> Does "global variables" mean "global instances such as
> cout, cerr defined in <iostream>" ?
>
> On 2002 March 19 Tuesday 23:36, Reinhard Katzmann wrote:
> > A.BalaSaraswathi wrote:
> > > Hello all,
> > >
> > >
> > > How to decalre and use global
> > > variables..............................
> >
> > You don't :) this would break the OOP paradigm.
> > You can specify the variables you use in one class file
> > only in you header file (for own classes) or in
> > Designer in the Object Explorer / Source View under
> > Class Variables.
> >
> > If you need access to them from other classes either
> > declare them public or (much better) create access
> > functions for them (aka setVar/getVar)
> >
> > Regards,
> >
> > Reinhard
Message 7 in thread
Hello all,
I am having two Qdialogs as form1 and form2.
In form1, i am having one combobox and one ok button.
I am selecting an item in combobox and maintaing it in one
variable.Depending upon the item selected in that combobox,when i click
the ok button, that variable value should be maintained in the form2.
How to do it.
Plz if any one knows this, expalin me detail.
Thank you in advance.
regards,
Saraswathi.
--
[ signature omitted ]
Message 8 in thread
Qt has a signal/slot mechanism which helps you to know when a button has
been clicked or a combobox item has changed. It is very flexible and easy to
use, but you should read a tutorial or look at some simple examples.
--
[ signature omitted ]
Message 9 in thread
Hello all,
I am having one QTable.
I have to get the position of the particular cell(row,column) whenever i
click the cell.
So i have to know about how to use the click event for QTable.
Plz give me the syntax for that event.
--
[ signature omitted ]
Message 10 in thread
Hello all,
I am having one table.
I ahve to set the font for the table at run time.
The following is the code i have written for setting the font for the
table at runtime.
QFont f("Tab_CK10",10,QFont::Bold);
strcpy(fontName,"Tab_CK10");
f.setFamily(fontName);
Table2->setFont(f);
Here Table2 is the table name.Tab_CK10 is my fontname.
But it is not invoked at the runtime.The correspondinf font is not set to
the table.
Plz tell me the reson and how to set the font at runtime for table......
--
[ signature omitted ]
Message 11 in thread
For to solve the problem, you must to reimplement the protected member
QTable::drawContents and to write this code under:
drawContents ( QPainter * p, int cx, int cy, int cw, int ch )
{
QFont f("Tab_CK10",10,QFont::Bold);
strcpy(fontName,"Tab_CK10");
f.setFamily(fontName);
p->setFont(f); //
}
Erick
----- Original Message -----
From: "A.BalaSaraswathi" <saraswathi@lantana.tenet.res.in>
To: <qt-interest@trolltech.com>
Sent: Wednesday, March 20, 2002 3:31 AM
Subject: How to set font for a table at runtime
> Hello all,
>
>
> I am having one table.
> I ahve to set the font for the table at run time.
>
> The following is the code i have written for setting the font for the
> table at runtime.
>
> QFont f("Tab_CK10",10,QFont::Bold);
> strcpy(fontName,"Tab_CK10");
> f.setFamily(fontName);
> Table2->setFont(f);
>
> Here Table2 is the table name.Tab_CK10 is my fontname.
>
>
> But it is not invoked at the runtime.The correspondinf font is not set to
> the table.
> Plz tell me the reson and how to set the font at runtime for table......
>
>
> --
>
> --
> List archive and information: http://qt-interest.trolltech.com
>
Message 12 in thread
hey all,
I am currently evaluating the Qt product, and have been building the mdi
example on several platforms to make sure that it fits our needs. Mac is my
last obstacle, but has proven to be a formidable one. Basically, what I've
done is add a .ui file (and accompanying dialog.h/cpp files) to the example
mdi app, and then I build the app and make sure it looks good on a specific
platform. I'm a Windows guy, so getting things to build on Solaris and Linux
was a bit of a chore, but I eventually got the Makefile to build and all was
good.
My problem with the Mac is that there are no Makefiles shipped with the
examples. So, I did a qmake -o Makefile mdi.pro and it generates a Makefile,
without any SOURCE, HEADER, etc. dependencies in it. I added the
dependencies but now I've found out it is missing one more thing.
In the "Build Rules" section, there is an entry
Makefile: mdi.app ../../qmake.cache \
$(QMAKE) mdi.app
however, there is no mdi.app descriptor in that rules section, so my make
fails. I've been surfing through the Qt site and google for a couple hours
now, but no luck in finding any examples of MacOS makefiles or any other
help. So, basically I have no idea what mdi.app should do, and I'm hoping
someone on this list can either pass along a couple example Makefiles, or
point me in a direction where I can find some stuff on my own.
Thanks in advance to anyone that can give some assistance.
Thanks for you time,
Matt Harp
mharp@seapine.SPAM.com
Message 13 in thread
the same way you declare global variables in C or C++
If you dont' know how to do that, then you should study and learn C and C++
before tackling QT.
----- Original Message -----
From: "A.BalaSaraswathi" <saraswathi@lantana.tenet.res.in>
To: <qt-interest@trolltech.com>
Sent: Tuesday, March 19, 2002 3:43 AM
Subject: Global variables
> Hello all,
>
>
> How to decalre and use global variables..............................
>
> --
>
> --
> List archive and information: http://qt-interest.trolltech.com
Message 14 in thread
To send a message from your worker thread (which for example performs a
time-consuming database lookup) back to the Qt main thread running the
main event loop, the class QThread provides the method postEvent(). The
classes that are interested in the posted event must provide an event
filter as described in QObject::installEventFilter(). They check for the
posted event and act appropriately.
Sending a message from the Qt main thread to the worker thread is done
as follows. You create a command object for your request and place it
into queue. The worker thread is waiting on a QWaitCondition until a new
command object is inserted into the queue. Then it removes the command
object from the queue and executes it. The worker thread executing the
command object uses postEvent() to send intermediate or final results
back to the Qt main thread. This solution is known as the ActiveObject
pattern, which is described in the book "Pattern-Oriented Software
Architecture: Patterns for Concurrent & Networked Objects" by Douglas
Schmidt et al. (http://www.cs.wustl.edu/~schmidt/POSA).
Best regards,
Burkhard
IKEGAMI Naoyuki wrote:
> Qt signal is not designed for intercommunication between
> threads/process. In other words, Qt signal is actually not
> a signal, it is only a fuction call.
>
> Keyword 'emit' is defined as empty, so "emit someSignal();"
> you wrote is just same as "someSignal();". The moc appends
> "someSignal()" implementation in *.moc.cpp file. In that
> code, "activate_signal("someSignal()");" is called, and
> connecting slots (their pointers are stored in a dictionary
> hashed by string) are called sequencially.
>
> So, in your case, a thread emitted a signal goes to a slot
> method which you expected is executed in another thread.
>
> For intercommunication between threads, other solutions
> like a condition variable, a mutex or a FIFO buffer are
> needed.
>
> Naoyuki
>
> On 2002 March 19 Tuesday 15:50, Greger Haga wrote:
> > Dear all,
> > I have a ( quite small abt 4100 lines ) application for
> > which I am concidering a multithreaded approach. One of
> > the options for this application is to do a search in its
> > data files, which can be of any number, thus the search
> > may take several seconds( GUI locks naturally) . So the
> > obvious thing is to make a QThread inherited class that
> > does the job of searching. For now the application is not
> > multithreaded, but single. I use signals and slots for
> > communication between objects that do the search, also
> > non-GUI objects. Therefore a few questions arise:
> >
> > Using signals and slots between threads, is that a save
> > way to do it? For each signal emitted ( from the searcher
> > class in this case ) should I use qApp->lock / unlock? (
> > as for now I am updating another object by sending it
> > signals from the searcher object , which would be in
> > another thread).
> > Is the qApp->lock/unlock a semaphore that also protects
> > QObject inherited objects, which in my case may be also
> > non-GUI objects?
> >
> > Anything else I should concider before going
> > multithreaded? Thank's for your time,
> > /G
>
> --
> List archive and information: http://qt-interest.trolltech.com
Message 15 in thread
Great! I appreciated your fine solution.
You say "Create a command object with value semantics
allocated on heap zone, and use QApplication event queue as
FIFO buffer", right?
I couldn't find out this solution and implemented my own
command/result queue with mutex in my application, and
executed periodical checking on that. But your way is much
better.
Thank you!
Naoyuki
On 2002 March 20 Wednesday 23:04, Burkhard Stubert wrote:
> To send a message from your worker thread (which for
> example performs a time-consuming database lookup) back
> to the Qt main thread running the main event loop, the
> class QThread provides the method postEvent(). The
> classes that are interested in the posted event must
> provide an event filter as described in
> QObject::installEventFilter(). They check for the posted
> event and act appropriately.
>
> Sending a message from the Qt main thread to the worker
> thread is done as follows. You create a command object
> for your request and place it into queue. The worker
> thread is waiting on a QWaitCondition until a new command
> object is inserted into the queue. Then it removes the
> command object from the queue and executes it. The worker
> thread executing the command object uses postEvent() to
> send intermediate or final results back to the Qt main
> thread. This solution is known as the ActiveObject
> pattern, which is described in the book "Pattern-Oriented
> Software Architecture: Patterns for Concurrent &
> Networked Objects" by Douglas Schmidt et al.
> (http://www.cs.wustl.edu/~schmidt/POSA).
>
> Best regards,
> Burkhard