Hi, I need a little help:
I got a file which gets from lirc new data all the time i press a key on my remote control. For example, I press the "1" key and the file contains "AN1", I press the "2" Key and the file gets overwritten with "AN2", and so on.
My Qt program should permanenty read this file out and send the content to a server via socket. Well, at the time this works as follow ("datei" is the file I read out):
void MainWindow::on_btnmonitor_clicked() // start file monitoring
{
{
while(1){
QFile file("datei");
// my file return;
while (!file.atEnd()) {
if (line.contains("AUS1")){ //check if file contains "AUS1"
char *buffer = "AUS1"; // send this to the buffer...
write(sockfd, buffer, strlen(buffer)); // and write out to the server.
}
if (line.contains("AN1")){
char *buffer = "AN1";
write(sockfd, buffer, strlen(buffer));
}
usleep(30000);
}
}
}
}
void MainWindow::on_btnmonitor_clicked() // start file monitoring
{
{
while(1){
QFile file("datei"); // my file
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
return;
while (!file.atEnd()) {
QByteArray line = file.readLine();
if (line.contains("AUS1")){ //check if file contains "AUS1"
char *buffer = "AUS1"; // send this to the buffer...
write(sockfd, buffer, strlen(buffer)); // and write out to the server.
}
if (line.contains("AN1")){
char *buffer = "AN1";
write(sockfd, buffer, strlen(buffer));
}
usleep(30000);
}
}
}
}
To copy to clipboard, switch view to plain text mode
As you can see, this code is horrible, not more than a general function test. The program is in an endless loop (but this doesn't matter, it has no other function) and my server gets flooded with messages all the time(that does matter). My goal is, that QtFileSystemwatcher monitors that file and only if there is a content-change the line should be sent to the server one time.
But I have no idea, i read the tutorial of QtFilesystemWatcher, but got no idea how to catch this "file change" signal in an if-command and send only the "codeword" in this file to my server when it has changed. Or, is there a easier, better way instead of Filesystemwatch? 
Help, understandable for a newbie would be very nice;-)
greets
Bookmarks