July 24, 2011

WilliamU WilliamU
Lab Rat
48 posts

QDomDocument’s setContent(QFile) failing with boost::interprocess timed_lock

 

Hi Guys,

I have this code extracted from a QThread’s run() :

  1. ...
  2. if (input->exists())
  3.     {
  4.         if (input->open(QFile::ReadOnly | QFile::Text))
  5.         {
  6.             try
  7.             {
  8.                 file_lock timeLock(m_FileName.c_str()) ;
  9.                 ptime pt = ptime(second_clock::local_time()) ;
  10.                 if (timeLock.timed_lock(pt += seconds(5)))
  11.                 {
  12.                     if (m_Model->setContent(input))
  13.                     {
  14.                        qDebug() << "Content Set" ;
  15.                     }
  16.                     else
  17.                     {
  18.                        qDebug() << "Unable set content" ;
  19.                     }
  20.                     timeLock.unlock() ;
  21.                 }
  22.                 else
  23.                 {
  24.                     qDebug() << "Unable to get lock!" ;
  25.                 }
  26.             }
  27.             catch (lock_exception& e)
  28.             {
  29.                 qDebug() << "Locking" << e.what() << m_FileName.c_str() ;
  30.             }
  31.             catch (interprocess_exception& e)
  32.             {
  33.                 qDebug() << "Reading" << e.what() << m_FileName.c_str() ;
  34.             }
  35.             input->close() ;
  36.         }
  37.     }

If you comment out the lines 10 and 20 it works on every execution of the thread. However, when the timed_lock is applied m_Model is unable to set the document’s content, with the appropriate message being displayed in the Application Output console.

Would anyone know why this is?
Is there away to find out why the content cannot be set?

 Signature 

Regards,

William

1 reply

July 25, 2011

WilliamU WilliamU
Lab Rat
48 posts

Well it appears that this is not what it seems! The issue lies with the timed locking of the file for output! I’ll look into it a bit more to see if I’ve made a screaming error and post back with an update.

Thanks for reading.

 Signature 

Regards,

William

 
  ‹‹ Qt + MySql plugin, license      RTTI for non-QObject classes ››

You must log in to post a reply. Not a member yet? Register here!