update text edit at run time.
-
@mbatra said in update text edit at run time.:
emit slotFileChanged("
Why emit?
Simply call slotFileChanged as normal method.
If it does not work: did you do any debugging? Is slotFileChanged called? What happens inside slotFileChanged (can the file be successfully opened?). -
Hi,
Yes, when I call emit slotFileChanged("D:/Putty_Log/Putty.log");, its called and file is also opened. But when the file contents are getting updated, then this signal doesn't getting emitted. Its emitted only once.
@mbatra There is NO need for emit at all!
I just realised that your code makes no sense:void MainWindow::onstartButtonClicked() { textEdit->show(); bool b = watcher->addPath("D:/Putty_Log/Putty.log"); qDebug()<<"\nAddPath Return Value = "<<b; emit slotFileChanged("D:/Putty_Log/Putty.log"); }
You need to call slotFileChanged in the slot connected to the signal from the watcher. Currently you call it in onstartButtonClicked - so why should it be called everytime the file is edited? Think about the logic.
-
If I call
connect(watcher, SIGNAL(fileChanged(QString)), this, SLOT(slotFileChanged(QString)));Signal doesn't get emitted at all.
@mbatra said in update text edit at run time.:
connect(watcher, SIGNAL(fileChanged(QString)), this, SLOT(slotFileChanged(QString)));
This ought be all you need. When the watcher sees a file change it emits the
fileChanged()
signal and yourslotFileChanged()
slot should be called. -
@mbatra said in update text edit at run time.:
connect(watcher, SIGNAL(fileChanged(QString)), this, SLOT(slotFileChanged(QString)));
This ought be all you need. When the watcher sees a file change it emits the
fileChanged()
signal and yourslotFileChanged()
slot should be called. -
-
@mbatra
Now that you have it working, how about changing over to New Signal Slot Syntax:connect(watcher, &QFileSystemWatcher::fileChanged, this, &MainWindow::slotFileChanged);
Use this instead of
SIGNAL
/SLOT()
syntax going forward for all yourconnect()
s, you will get e.g. compile-time checking that the signal and slot methods and arguments match. -
@mbatra
Now that you have it working, how about changing over to New Signal Slot Syntax:connect(watcher, &QFileSystemWatcher::fileChanged, this, &MainWindow::slotFileChanged);
Use this instead of
SIGNAL
/SLOT()
syntax going forward for all yourconnect()
s, you will get e.g. compile-time checking that the signal and slot methods and arguments match. -
@mbatra
Now that you have it working, how about changing over to New Signal Slot Syntax:connect(watcher, &QFileSystemWatcher::fileChanged, this, &MainWindow::slotFileChanged);
Use this instead of
SIGNAL
/SLOT()
syntax going forward for all yourconnect()
s, you will get e.g. compile-time checking that the signal and slot methods and arguments match.Hi,
I am facing another issue. File contents are not getting updating dynamically. If I add anything from the keyboard into the txt file slotchanged signal gets emitted. But if I run a batch file and that batch file creates a log file which I am reading into my application, contents are getting updated in the log file but text edit not getting updated at the same time.
Any help would be appreciated.
-
Hi,
I am facing another issue. File contents are not getting updating dynamically. If I add anything from the keyboard into the txt file slotchanged signal gets emitted. But if I run a batch file and that batch file creates a log file which I am reading into my application, contents are getting updated in the log file but text edit not getting updated at the same time.
Any help would be appreciated.
@mbatra Do you mean the file does not exist at the beginning, but is created to some later point in time? If that is the case then I suggest to also add the folder where the file is created to QFileSystemWatcher, so that you get a notification when the file is created in that folder.
Because if you read the documentation:bool QFileSystemWatcher::addPath(const QString &path) Adds path to the file system watcher if path exists. The path is not added if it does not exist
"if path exists. The path is not added if it does not exist"
-
Hi,
I am facing another issue. File contents are not getting updating dynamically. If I add anything from the keyboard into the txt file slotchanged signal gets emitted. But if I run a batch file and that batch file creates a log file which I am reading into my application, contents are getting updated in the log file but text edit not getting updated at the same time.
Any help would be appreciated.
@mbatra
Exactly as @jsulm has written. If the file to be monitored does not yet exist you cannot place aQFileSystemWatcher
on it. You have to watch the directory first to see file creation viadirectoryChanged()
. Only once it has been created can you then start to monitor the file forfileChanged()
, so a two-step process for your case. -
@mbatra
Exactly as @jsulm has written. If the file to be monitored does not yet exist you cannot place aQFileSystemWatcher
on it. You have to watch the directory first to see file creation viadirectoryChanged()
. Only once it has been created can you then start to monitor the file forfileChanged()
, so a two-step process for your case.