QFileSystemWatcher - how to set mainWindow visible instead ofwith QFSW
Hi all,
how to set MainWindow ui visible where I create widget elements instead of with QFileSystemWatcher gui which pops up when I use object = new QFileSystemWatcher();
Hope you understand my problem. My UI /where I have visual elements) never shows up, only QFSWatcher window pops up when Im trying to listen signals for directory or file changes.
Re: QFileSystemWatcher - how to set mainWindow visible instead ofwith QFSW
QFileSystemWatcher is in the QtCore module: it has no GUI.
You will have to explain what you are doing, preferrably with the relevant code (in [code]...[/code] tags), and what you are seeing
1 Attachment(s)
Re: QFileSystemWatcher - how to set mainWindow visible instead ofwith QFSW
Dear all,
regarding my opening post I'm sorry to everybody who read it. I was quite tired when typed those bollocks. Intention was to have watcher object in main window that listens for sqlite file for changes, so user can use UI while those changes happen in paralel...
Here how I starded it.
Code:
#ifndef DIALOG_H
#define DIALOG_H
#include "ui_dialog.h"
#include <QDialog>
#include<QtGui>
#include<iostream>
#include <QtCore>
#include <QMessageBox>
//#include <QtWidgets>
#include <QThread>
#include <QtSql/QSqlDatabase>
#include <QSqlQuery>
#include <QDateTime>
#include <QSqlError>
namespace Ui {
class Dialog;
//const QString dbName = "/home/goran/FileTrigger/table";
}
{
Q_OBJECT
public:
bool createConnection()
{
//db.setHostName("localhost");
db.setDatabaseName("/home/goran/FileTrigger/table");
//db.setUserName("user");
//db.setPassword("pasw");
if (!db.open()) {
db.lastError().text());
return false;
}
return true;
}
void connClose(){
db.close();
}
public:
explicit Dialog
(QWidget *parent
= 0);
~Dialog();
private slots:
void fileChangedSlot(const QString&)
{
ui->label->setText("Detected File Change..."); //Detected File Change Promjena u bazi je zabilježena
//ui->label->setText("change detected...");
createConnection();
query2.exec("SELECT lot, lineNo FROM data where idData=1");
while (query2.next()) {
QString title2
= query2.
value(0).
toString();
int pLine2 = query2.value(1).toInt();
ui->lineEdit->setText(title2);
ui
->lineEdit_2
->setText
(QString::number(pLine2
));
}
connClose();
}
void dirChangedSlot(const QString&)
{
int count=0;
createConnection();
query.prepare("select lot, lineNo from data");
if(query.exec()){
//int count=0;
while (query.next()) {
qDebug() << count++;
}
query.finish();
}
ui->label->setText("Detected Directory Change...");
connClose();
}
//havent use this so far..
bool connPrinterOne(){
return true;
}
void on_pushButton_clicked();
private:
Ui::Dialog *ui;
//bool connPrinter1;
};
#endif // DIALOG_H
Code:
#include "dialog.h"
#include "ui_dialog.h"
ui(new Ui::Dialog)
{
ui->setupUi(this);
//Coloring Qlabel...
//ui->labelOne->setAutoFillBackground(true); // IMPORTANT! I've done it in UI
ui->labelOne->setPalette(pal);
ui->label->setText("Started");
ui->lineEdit->setText("Insert series"); //Unesi lot
ui->lineEdit_2->setText("Insert date");//Unesi datum
QString pathToFile
="/home/goran/FileTrigger/table";
watcher->addPath(pathToFile);
connect(watcher,
SIGNAL(fileChanged
(const QString &)),
this,
SLOT(fileChangedSlot
(const QString &)));
//connect(watcher,SIGNAL(directoryChanged(const QString&)),this,SLOT(dirChangedSlot(const QString&)));
}
Dialog::~Dialog()
{
delete ui;
}
void Dialog::on_pushButton_clicked()
{
ui->label->setText("");
ui->lineEdit->setText("clear previous text");
ui->lineEdit_2->setText("clear previous text");
}