Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 139
Registered: ‎05-24-2011
My Device: Z30 running 10.2 and Playbook 4GLTE running OS2.1
My Carrier: rogers

QFileSystemWatcher

Hi gang,

 

it's just not my night.. 

 

anyone know why this wouldn't work?

 

	
.......
bool result;
QFileSystemWatcher * fsWatcher = new QFileSystemWatcher(); fsWatcher->setParent(this); fsWatcher->addPath(QDir::currentPath() + "/shared/misc/text.txt"); fsWatcher->addPath(QDir::currentPath() + "/shared/misc"); qWarning() << "fsWatcher is watching files: " << fsWatcher->files() << " and dirs: " << fsWatcher->directories(); result = connect(fsWatcher, SIGNAL(fileChanged(QString)), this, SLOT(onFilesChanged(QString))); Q_ASSERT(result); result = connect(fsWatcher, SIGNAL(directoryChanged(QString)), this, SLOT(onFilesChanged(QString))); Q_ASSERT(result); << change file or dir here >> void WorkManager::onFilesChanged(QString changedFile) { qWarning() << "WorkManager::onFilesChanged(), file that changed is: " << changedFile; }

 

I could have sworn this was working a few days ago, but now, nothing happens when the file is edited.

 

I'm assuming that the connects are being made as the app doesn't stop at the Q_ASSERT statements.

 

 

bron: a cron-like scheduler for BlackBerry 10
http://apps.oddelement.com
Retired
Posts: 571
Registered: ‎06-25-2010
My Device: Z10
My Carrier: Vodafone

Re: QFileSystemWatcher

[ Edited ]

Hi

 

have you remembered to grant permissions to your shared files with the following in your bar-descriptor.xml file?

 

<permission>access_shared</permission>

 

 

Regards

 

Martin

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Retired
Posts: 571
Registered: ‎06-25-2010
My Device: Z10
My Carrier: Vodafone

Re: QFileSystemWatcher

[ Edited ]

p.s. do you see any errors in the console?

 

If your file does not actually exist then you'll get an error message like this:

 

QFileSystemWatcher: failed to add paths: /accounts/1000/appdata/com.example.FileSystemWatcher.testDev_stemWatcher241cea0_/shared/misc/text.txt

  

The documentation for QFileSystemWatcher mentions this:

 

http://harmattan-dev.nokia.com/docs/library/html/qt4/qfilesystemwatcher.html#addPath

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Developer
Posts: 139
Registered: ‎05-24-2011
My Device: Z30 running 10.2 and Playbook 4GLTE running OS2.1
My Carrier: rogers

Re: QFileSystemWatcher

Hi,

Thanks for your replies.

I do have shared access enabled, and there are no errors.

Incidentally, I tries rebooting my phone and it works again. Not sure what was wrong. Need to figure out why it stopped working, but at least it is working again (with no changes to the code).
bron: a cron-like scheduler for BlackBerry 10
http://apps.oddelement.com
Retired
Posts: 571
Registered: ‎06-25-2010
My Device: Z10
My Carrier: Vodafone

Re: QFileSystemWatcher

OK, that's most odd. Glad it's working now though. If you have further problems, please post again and we'll see what can be done.

 

All the best

 

Martin

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Developer
Posts: 1,632
Registered: ‎07-14-2008
My Device: Z10
My Carrier: Fido

Re: QFileSystemWatcher

I'm having trouble detecting a directory change outside of the  /accounts/1000 space.

 

I want to watch a directory in the /usr directory.

 

Is this allow or are we limited to the /accounts/1000 folder?

Highlighted
Retired
Posts: 571
Registered: ‎06-25-2010
My Device: Z10
My Carrier: Vodafone

Re: QFileSystemWatcher

No, your app will not have permission for this and is limited to the shared directory and the data in its own "sandbox". See https://developer.blackberry.com/native/documentation/cascades/device_platform/data_access/file_syst...

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim