Results 1 to 3 of 3

Thread: QFileSystemWatcher - how to set mainWindow visible instead ofwith QFSW

  1. #1
    Join Date
    Aug 2013
    Posts
    13
    Thanks
    2
    Qt products
    Qt5

    Default 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.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default 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

  3. #3
    Join Date
    Aug 2013
    Posts
    13
    Thanks
    2
    Qt products
    Qt5

    Default 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.
    Qt Code:
    1. #ifndef DIALOG_H
    2. #define DIALOG_H
    3. #include "ui_dialog.h"
    4. #include <QDialog>
    5. #include<QtGui>
    6. #include<iostream>
    7. #include <QtCore>
    8. #include <QMessageBox>
    9. //#include <QtWidgets>
    10. #include <QThread>
    11. #include <QtSql/QSqlDatabase>
    12. #include <QSqlQuery>
    13. #include <QDateTime>
    14. #include <QSqlError>
    15.  
    16. namespace Ui {
    17. class Dialog;
    18. //const QString dbName = "/home/goran/FileTrigger/table";
    19. }
    20.  
    21. class Dialog : public QDialog
    22. {
    23. Q_OBJECT
    24. public:
    25. bool createConnection()
    26. {
    27. QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    28. //db.setHostName("localhost");
    29. db.setDatabaseName("/home/goran/FileTrigger/table");
    30. //db.setUserName("user");
    31. //db.setPassword("pasw");
    32. if (!db.open()) {
    33. QMessageBox::critical(0, QObject::tr("Database Error"),
    34. db.lastError().text());
    35. return false;
    36. }
    37. return true;
    38. }
    39. void connClose(){
    40. db.close();
    41. db.removeDatabase(QSqlDatabase::defaultConnection);
    42. }
    43.  
    44. public:
    45. explicit Dialog(QWidget *parent = 0);
    46. ~Dialog();
    47.  
    48.  
    49. private slots:
    50.  
    51. void fileChangedSlot(const QString&)
    52. {
    53. ui->label->setText("Detected File Change..."); //Detected File Change Promjena u bazi je zabilježena
    54. QThread::msleep(100);
    55. //ui->label->setText("change detected...");
    56. createConnection();
    57. QSqlQuery query2;
    58. query2.exec("SELECT lot, lineNo FROM data where idData=1");
    59. while (query2.next()) {
    60. QString title2 = query2.value(0).toString();
    61. int pLine2 = query2.value(1).toInt();
    62. ui->lineEdit->setText(title2);
    63. ui->lineEdit_2->setText(QString::number(pLine2));
    64. }
    65. connClose();
    66. }
    67.  
    68. void dirChangedSlot(const QString&)
    69. {
    70. int count=0;
    71. createConnection();
    72. QSqlQuery query;
    73. query.prepare("select lot, lineNo from data");
    74. if(query.exec()){
    75. //int count=0;
    76. while (query.next()) {
    77. qDebug() << count++;
    78. }
    79. query.finish();
    80. }
    81. ui->label->setText("Detected Directory Change...");
    82. connClose();
    83. }
    84. //havent use this so far..
    85. bool connPrinterOne(){
    86. return true;
    87. }
    88. void on_pushButton_clicked();
    89.  
    90. private:
    91. Ui::Dialog *ui;
    92. QLabel* label;
    93. QString dbName;
    94. //bool connPrinter1;
    95.  
    96. };
    97.  
    98. #endif // DIALOG_H
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. #include "dialog.h"
    2. #include "ui_dialog.h"
    3.  
    4.  
    5. Dialog::Dialog(QWidget *parent) :
    6. QDialog(parent),
    7. ui(new Ui::Dialog)
    8. {
    9. ui->setupUi(this);
    10. //Coloring Qlabel...
    11. //ui->labelOne->setAutoFillBackground(true); // IMPORTANT! I've done it in UI
    12. QPalette pal = ui->labelOne->palette();
    13. pal.setColor(QPalette::Window, QColor(Qt::green));
    14. ui->labelOne->setPalette(pal);
    15.  
    16. ui->label->setText("Started");
    17. ui->lineEdit->setText("Insert series"); //Unesi lot
    18. ui->lineEdit_2->setText("Insert date");//Unesi datum
    19.  
    20. QString pathToFile ="/home/goran/FileTrigger/table";
    21. watcher->addPath(pathToFile);
    22. connect(watcher,SIGNAL(fileChanged(const QString &)),this,SLOT(fileChangedSlot(const QString &)));
    23. //connect(watcher,SIGNAL(directoryChanged(const QString&)),this,SLOT(dirChangedSlot(const QString&)));
    24. }
    25.  
    26. Dialog::~Dialog()
    27. {
    28. delete ui;
    29. }
    30.  
    31. void Dialog::on_pushButton_clicked()
    32. {
    33. ui->label->setText("");
    34. ui->lineEdit->setText("clear previous text");
    35. ui->lineEdit_2->setText("clear previous text");
    36. }
    To copy to clipboard, switch view to plain text mode 
    Attached Files Attached Files
    Last edited by anda_skoa; 7th February 2016 at 14:00. Reason: missing [code] tags

Similar Threads

  1. Replies: 3
    Last Post: 2nd January 2018, 13:04
  2. Replies: 10
    Last Post: 7th December 2011, 21:05
  3. Replies: 0
    Last Post: 6th November 2011, 09:22
  4. Replies: 2
    Last Post: 19th August 2008, 09:46
  5. QFileSystemWatcher
    By minty in forum Qt Programming
    Replies: 13
    Last Post: 22nd May 2007, 15:39

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.