Qt-interest Archive, February 2007
QFileSystemWatcher problem
Message 1 in thread
Hi,
I wrote a little class called StyleSheetLoader which is intended to load
a QSS file and apply it to widgets or an application. For testing QSS, I
also wanted to make it smart: when the file is changed (using a text
editor, not inside the application), my loader should reload it and
reapply the style sheet. To do so, I use a QFileSystemWatcher which
watches my QSS file. I connected the #fileChanged signal to a reload
slot wherein the file is read into a string. Problem is: when this slot
is called, the file is sometimes unchanged (the content is the same as
before changing it), and sometimes does not exist at all (at least
according to QFile::exists). When I set a break point in this slot, it
works. So I think it's a timing problem because while I'm debug-stepping
through the code, the OS (Windows XP in my case) has time to close the
file...
Anyway, does someone have a clue how I might get around this problem?
I'd have tried to QThread::wait, but it seems to be prohibited to do
that with the current thread.
Thanks,
M
--
[ signature omitted ]
Message 2 in thread
Hi,
> Anyway, does someone have a clue how I might get around this problem?
> I'd have tried to QThread::wait, but it seems to be prohibited to do
> that with the current thread.
It's possible but you do have to use a trick: inherit QThread and make
this protected function public.
--
[ signature omitted ]
Message 3 in thread
> Anyway, does someone have a clue how I might get around this problem?
> I'd have tried to QThread::wait, but it seems to be prohibited to do
> that with the current thread.
You could also use a QTimer signal.
Connect your fileChanged signal to a slot that starts the timer and
connect your timer signal to the reload slot.
just my 2p.
Peter Prade
--
[ signature omitted ]
Message 4 in thread
Peter Prade wrote:
>> Anyway, does someone have a clue how I might get around this problem?
>> I'd have tried to QThread::wait, but it seems to be prohibited to do
>> that with the current thread.
>
> You could also use a QTimer signal.
>
> Connect your fileChanged signal to a slot that starts the timer and
> connect your timer signal to the reload slot.
>
> just my 2p.
> Peter Prade
Good idea, thanks :)
M
--
[ signature omitted ]