Showing posts with label qt. Show all posts
Showing posts with label qt. Show all posts

Thursday, March 15, 2012

Kbd++ released : Track global Toggle key events

Finally after a lot of development effort and study of OS internals, Kbd++ is being released.

Essentially it is ...........

An utility to track the toggle key(CAPS, NUM, SCROLL) status of keyboard. This is particularly useful for Wireless keyboard users as wireless keyboards have no LEDs. Status of the LEDs is indicated using three icons in the System Tray with Balloontips(optional). It is being developed on C++/Qt and will currently target Windows and Linux boxes. Platform specific code are implemented using Win32 and X11 APIs.

Currently it is only supporting MS Windows. Windows implementation is based on Named Pipes (for IPC ) and Windows Hooks (for capturing global events). Linux implementation is on way and hopefully will be completed shortly.

Make sure you run the correct binaries on the correct architecture (x86/amd64), else the explorer might hang.



It is freely available at :
Qt Apps Kbd++

The source is hosted on the mercurial based public repository at BitBucket:
Kbd++ Source

The Linux implementation is yet a gray area........ need more study on that. An easy way out is monitoring the key state at regular intervals. However that will increase the CPU utilization. Hence need to look for some system specific way to do it.

One major disappointment during the life of the project has been a strange runtime error while using QLocalSoket from the injected DLL, which in debug mode said :

warning: ASSERT failure in QWinEventNotifier::QWinEventNotifier(): "Cannot creat
e a win event notifier without a QEventDispatcherWin32", file kernel\qwineventno
tifier_p.cpp, line 74 



Qt Centre had a long discussion thread on this, which says its a probable Qt bug ...
Qt Centre discussion thread

I had too replace the entire named pipe client implementation in the injected DLL, using Win32 API s for the same.

Tuesday, March 13, 2012

Error while bulding 64 bit Qt lib 4.8.0 on Windows: “Perl not found in environment – cannot run syncqt”

Just encountered this error while trying to build the 64bit version of the Qt lib 4.8.0 on Windows:
The configure tools stopped saying : “Perl not found in environment – cannot run syncqt”"

If you do not want to install Perl, easy solution to this is just deleting the syncQt.bat from the $QtDir\bin directory and running configure again.

Tuesday, September 7, 2010

Qt-Creator: Using native/platform specific library

Unfortunately, Qt-Creator so far does not provide for addition of native/platform specific dependencies from its UI. The only way to do it is by editing the .pro file manually.

An example:

If the Win32 API GetKeyState() contained in User32.dll is used in your code, append the following lines to the .pro file of your project:

win32 {

LIBS += User32.lib

}

Simlarly, an Unix specific dependency will go into a block like this&

unix{

LIBS += -L/usr/local/lib -lmath

}

Tuesday, August 25, 2009

A Steganography Tool

Check my cute little creation ;)

Stegosaurus 1.0 is a tool to perform steganography on 24-bit BMP files.

Use this to hide and recover any type of file to and from a selected BMP image, without altering the original size of the image

For details of the steganography process used visit

http://www.garykessler.net/library/steganography.html

Tuesday, March 24, 2009

QSqlDatabase closing problem while using QSqlTableModel with QTableView

Problem:

I was working on a application that deals with multiple databases when I encountered a problem while closing a connection. Even if I close the connection it seemed to be active and hence was not letting itself to be copied.
The code I used typically was :

QSqlDatabase db(Conn);

....................................
....................................

....................................
db.close();



The copying problem caused due to the connection remaining active got solved after enclosing the queries in proper scope. eg.

{
QSqlDatabase db = QSqlDatabase::database("sales");
QSqlQuery query("SELECT NAME, DOB FROM EMPLOYEES", db);
}
// Both "db" and "query" are destroyed because they are out of scope
QSqlDatabase::removeDatabase("sales"); // correct

But the problem reappeared, after I implemented a QTableView with a QSqlTableModel:

QSqlTableModel *model =new QSqlTableModel(this, Conn) ;
model->setTable("student");
model->setFilter("student_id=" +QString::number(Cmn_Global::student_id ));
model->setSort(3, Qt::AscendingOrder);
model->setEditStrategy(QSqlTableModel:: OnFieldChange);
model->select();
............................
...........................
ui.tableView->setModel(model);//view is the QTableView object

Calling db.close() failed to close the connection as the real time querying between the Model and the View, which was not possible for me to enclose within scope.


Solution:
The only solution that emerged was to kill the connection manually, by deleting the QSqlTableModel pointer related to the view using the following code:
QSqlTableModel* model= dynamic_cast (ui.tableView->model());
delete model;

And then calling the close method on the database.

The database can then be smoothly copied as the connection was no more active.

Wednesday, March 4, 2009

Word Wrap Code

This is a code to wrap a QString if it exceeds a particular number of characters per line, without splitting any word into different lines.

Signature : QString wordWrap(const QString &str, int wrapLength)
Argument : 1. The QString to be wrapped
2. The permissible number of characters per line.

Return Value: The wrapped QString

QString wordWrap(const QString &str, int wrapLength)
{
QString tempStr= str;
int len = str.length(), pos= (wrapLength>1)?wrapLength -1:1;

while(pos < len-1){

int tempPos=pos;
while(tempStr.at(tempPos)!=' ' && tempPos > 0){

tempPos--;
}
if(tempPos > 0)pos=tempPos;

tempStr.replace(pos,1,'\n');
pos+=pos;
}

return tempStr;
}

Directory Copy code

This is a directory copy code . It copies all the files or subdirectories under the destination directory to the target directory:

Signature : void copyDir(QString, QString)
Argument : 1. Path of the source directory
2. Path of the destination directory (if the destination does not exist, it is created automatically)

Return Value: void

void copyDir(QString src, QString dest)
{
//Check whether the dir directory exists
if(QDir(src).exists()){
if(!QDir(dest).exists()){
QDir().mkpath(dest);
}

//Construct an iterator to get the entries in the directory
QDirIterator dirIterator(src);

while (dirIterator.hasNext()) {
QString item= dirIterator.next(), fileName= dirIterator.fileName();
QFileInfo fileInfo= dirIterator.fileInfo();

if(fileName!="." && fileName!=".."){

//If entry is a file copy it
if(fileInfo.isFile()){
QFile::copy(item, dest+"/"+ fileName);
}
//If entry is a directory, call the deltree function over it again to traverse it
else
copy(item, dest+ "/"+ fileName);
}
}
}else return;

}

Monday, March 2, 2009

Directory Tree Deletion Code (rmdir or rm -f equivalent)

This is a directory removal code (rm -r or rmdir equivalent). It deletes all the files or subdirectories under the directory pointed to and also deletes the directory itself:

Signature : bool delTree(QString)
Argument : Path of the directory to be deleted as QString
Return Value: true on success/false on error

bool delTree(QString dir)
{
//Check whether the dir directory exists
if(QDir(dir).exists()){

//Construct an iterator to get the entries in the directory
QDirIterator dirIterator(dir);

while (dirIterator.hasNext()) {

//Get the file information
QString item= dirIterator.next(), fileName= dirIterator.fileName();
QFileInfo fileInfo= dirIterator.fileInfo();

//If entry is a file delete it
if(fileName!="." && fileName!=".."){

if(fileInfo.isFile()){
QFile::remove(item);
}
//If entry is a directory, call the deltree function over it again to traverse it
else if(fileInfo.isDir()){
delTree(item);
}
}
}
}else
return false;

//Move up the directory hierarchy by one level
//Delete the current directory
QDir currentDir(dir);
currentDir.cdUp();
return currentDir.rmdir(dir);

}