blog about qt and qxt related stuff

Montag, 27. August 2007

About locks and validations

Hi there,

last time i added two new classes to Qxt:
  • QxtStringValidator
  • QxtFileLock.

QxtStringValidator was initialliy a class to validate over a QStringList, but this was not really worth to put it into Qxt. So i decided to make it more powerfull. Now it provides a String based validation over a QAbstractItemModel. :


QxtStringValidator validator = new QxtStringValidator();
validator->setLookupModel(myCoolCustomModel);

/*now we have to choose the right column
this will lookup in column 3, starting from row 0
*/
validator->setStartModelIndex(myCoolCustomModel->index(0,3));
//case insensitive lookup
validator->setCaseSensitivity(Qt::CaseInsensitive);
//and now set the validator to a lineEdit
lineEdit->setValidator(validator);

There are some other features like :
  • wrapping lookup
  • case sensitive/insensitive lookup
  • recursive lookups
  • looking up different model rows
And it is also possible to use a QStringList as data source (never forget your roots ;) ).

QxtFileLock is something i had in my mind for a long time since i thought about writing a isam filemanager based on QT. The first thing i realized was that there is no file lock available in Qt. Well it is possible but not using a nice crossplattform class like Qt offers them. So here is my solution for that:


void doSomeOpOnFile()
{
off_t lockStart = 0x10;
off_t lockLength = 20;
QxtFileLock readLock(&file,
lockStart,lockLength,QxtFileLock::ReadLock);
if(readLock.lock())
{
/*do some read operations*/
/*the lock gets cleaned up after it is deleted it is not needed to call unlock()*/
QxtFileLock writeLock (
&file,lockStart,lockLength,QxtFileLock::WriteLock);
if(writeLock.lock())
{
/*do some write operations*/
}
}
/*in this case we don't have to care about releasing the lock. QxtFileLock will do it when the instance is destroyed*/
}

I had to do some extra work on *nix based systems. On *nix a lock does not behave like a normal unix lock. In fact on *nix locks are process wide, means a process can get a lock on a file as often as it wants to. With QxtFileLock this is not possible, locks are threads and handles bound. That means: A Thread can writelock the same region of a file twice only if it uses the SAME handle. If a different handle holds the lock a call to lock() will fail.
On *nix we use fcntl and on windows LockFileEx to implement the locking stuff.

Attention: don't mix QxtFileLock and lockf or flock on linux they are NOT compatible.
Also use only fcntl to lock the files in other apps.

Well i hope these two classes can go into the 0.2.4 release.
Due to vacation and other things i had to do the QxtScheduleView did not make it into the trunk.

zbenjamin
"your friendly developer from the neighbourhood"

Montag, 23. Juli 2007

The raise of QxtScheduleView







After long time of developing (well the real work did not took so long, but there were so much other things to do) i have some working QxtScheduleView class.
I already used it in one of my other apps and it worked nice ;).

Its a plannig app for modelplane shows.The Item Color indicates collisions of the plane's rc - quartz. So yellow indicates it may work, and red ... well i think you know the answer.

Now after i got this stuff working i have to refactor the class and that will take some time.

I'm not shure if i can put QxtScheduleView in the next release of libqxt.
But it will go into trunk in the next weeks. It also lacks all kind of docs so noone will know how to use it.
After i have QxtScheduleView finished for trunk i will start hacking the QxtScheduleWidget . It will have a internal Model and QxtScheduleWidgetItem that will make your life easier.

Well if someone wants to have a look at the current state,
the source can be checked out of my repository:

zbenjamin's sandbox
(https://libqxt.svn.sourceforge.net/svnroot/libqxt/sandbox/zbenjamin/QxtScheduleView/)

cya zbenjamin
"your friendly developer from the neighbourhood"