I am writing a new platform plugin for qt, i am trying to understand what is the "processEvents" virtual method supposed to do ?
my requirement is that i receive events on a file descriptor and am supposed to translate them to qt gui events and pass them over to the qt. pls advise.
From documentation http://qt-project.org/doc/qt-4.8/qcoreapplication.html#processEvents :
Processes all pending events for the calling thread according to the specified flags until there are no more events to process.
You can call this function occasionally when your program is busy performing a long operation (e.g. copying a file).
This is probably not what you are looking for. Based on the short description of your problem, it seems to me that you want Linux's poll(). http://linux.die.net/man/2/poll
You can use a QSocketNotifier for this. Note that a QSocketNotifier takes a file handle only on Unix systems. On Windows, it takes a special winsock handle that is not a generalized HANDLE to an event object, neither is it a file handle. Don't worry about processEvents, it's not relevant to your problem.
Related
I have a PAM application that makes use of a particular PAM module for authentication chores. My question is, what is the best for the module to share an arbitrary string of bytes with the application?
My understanding of the PAM API is that, in general, the application must use the pam_get_item() call in order to obtain data from the module. However, the item types that can be shared are very limited, and they do not seem to accommodate for what I need - with the possible exception of the PAM_CONV item type. If anybody in this forum has experience with this kind of thing their feedback would be much appreciated.
After some experimentation I think I found the answer. In essence, the application has to define a PAM conversation callback in which a pointer to a data buffer is provided. The PAM module has to invoke the callback at the appropriate time, and copy the appropriate data into that buffer. The application will simply obtain the desired data by reading the contents of the buffer.
This will of course have to be carefully choreographed by the application, and the module may have to be modified to invoke the callback at the right time. The idea is simple though.
I am learning a lot as a result of posting to this forum, even if I don't seem to be getting any feedback when it comes to PAM-related questions.
I think you can use PAM_CONV. as it says:
The PAM library uses an application-defined callback to allow a direct
communication between a loaded module and the application. This
callback is specified by the struct pam_conv passed to pam_start(3) at
the start of the transaction.
I am trying to watch a log file using QFileSystemWatcher but fileChanged signal is not consistently emitted every time the log file is modified. Any idea how QFileSystemWatcher determines if a file is modified (on windows)?
QFileSystemWatcher's performance is entirely dependent on what the underlying platform provides. There are in general absolutely no guarantees that if one process is writing to a file, some other process will see these changes immediately. The behavior of QFileSystemWatcher may be informing you of that fact. The log writing process might elect to flush the file. Depending on the platform, the semantics of a flush might be such that when flush() returns, other processes are guaranteed to be able to see the changes made to the file prior to flush(). If so, then you'd expect QFileSystemWatcher to notify you of the changes.
As the platforms get new features, QFileSystemWatcher may lag in its implementation of new filesystem notification APIs. You'd need to read its source to figure out if it supports everything your platform of choice provides in this respect.
You need to qualify QFileSystemWatcher's behavior on each platform you intend to support. You may find out that explicitly polling a file information periodically may work better in some cases - again, the choice between polling and QFileSystemWatcher should be made on a platform-by-platform basis, as polling might incur unnecessary overheads if the watcher works OK on a given platform.
Let's say when user clicks a button an (slow) operation is performed involving database access. The problem is that the GUI becomes unresponsive if I call the operation directly.
ui->comboBox->addItems(obj->getThingsFromDatabase())
I've also tried with signals/slots, emit a request to obj and then wait his response (another signal). Anyway, the result was the same, unresponsive GUI.
What should be the approach for this issue?
Best way to deal with it is to use another thread for getting things from database.
Here is really good guide how to use threads in Qt:
threading basics in Qt4
I am trying to implement just half of the SNMP functionality. On certain events, I want to create trap corresponding to each event. I am using C and Linux.
What would be the simplest way to achieve this? Do I need to use any open source utilities?Some of the events that I want to notify are very specific to my application. How to go about implementing this case?
I am new to SNMP. I have couple of basic questions: How agent and manager figure about what property i.e. object is being referred to? Do they both parse the MIB? How is MIB shared between agent and manager?
The easiest way is to execute Net-SNMP executable called snmptrap,
http://www.net-snmp.org/tutorial/tutorial-5/commands/snmptrap.html
Of course, you can also link to its underlying library so as to call the C functions directly.
About your basic questions on SNMP, you should start from a book, such as Essential SNMP or Understanding SNMP MIBs.
I have a process, and I'd like to check whether it is running or not, and take a decision in that direction, i.e., I'd like to check for running instances of this application, from another instance.
I can have 2 instances of the application running, dealing with 2 types of data. When a 3rd instance opens, it needs to check if another instance of its type ( from the 2 types already created ) is already running. If so, the new one needs to close down and send a message to the already running instance of its type.
Because of this, I think QtSingleApplication will not work.
I wish to create a System wide mutex and have the check done that way, but I've not seen any System wide mutex in Qt.
There is QMutex, which is only for threads of an application.
There is also something called QSystemMutex when I search online, but I suppose that's a custom solution? I didn't find it in my Qt installation or the assistant.
So is there any way I can create a System wide mutex using Qt, please?
Mutexes are defined to be used as a object in one process. You are looking for a solution outside the process.
An simple solution would be to use the filesystem. Create a file and delete it when the process stops. This can be harder though when multiple processes are running from different directories or when the application crashes.
An more advanced solution is to use a shared memory object. These objects exist outside the process, and can be checked and modified from any process. An example on shared memory for QT can be found here:
http://doc.qt.digia.com/4.7-snapshot/ipc-sharedmemory.html
You can definitely do that with QtSingleApplication. Nothing obliges you to terminates if the application is already running. You can define a bootstrap protocol on top of what QtSingleApplication offer you, ie you use its api as a locking primitive.
What you can do is send a message with a specific type to the running instance, for example the string representation of the type. It is simple: You send a message to the running instance and he tells you if you are welcome or not.
Each time an application starts, it listen to messages (even if there is one running). He can ack only one message if the type differs his.
If there is no application running he goes straight to doing his job.
If there is an application running, he send an hello message (his type for instance) and wait for ACK, NACK or timeout. You decide what to do if it timeouts.
If you are waiting for a reply and you recieve an hello, you refuse.
ps: What you describe is not exactly a mutex. the following code
int main(int argc, char **argv) {
QtSingleApplication app(argc, argv);
if (app.isRunning())
return 0;
//blah blah blah
}
is already a mutex.