Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Tail-f function in qt
Forum Updated to NodeBB v4.3 + New Features

Tail-f function in qt

Scheduled Pinned Locked Moved General and Desktop
32 Posts 7 Posters 14.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    devfeel
    wrote on last edited by
    #20

    The below code is giving error...can you please help
    @QTextStream in(stdin);
    QObject::connect(in, SIGNAL(readyRead()), this, SLOT(readcsv()));@

    error: no matching function for call to 'MainWindow::connect(QTextStream&, const char [13], MainWindow* const, const char [11])'

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #21

      QTextStream does not have a readyRead signal, QFile does (from QIODevice).

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • D Offline
        D Offline
        devfeel
        wrote on last edited by
        #22

        Evn this is not working...its not entering readcsv()
        @ QFile file("alert.csv");

        file.open(QIODevice::ReadOnly | QIODevice::Text);

        QObject::connect(&file,SIGNAL(readyRead()),  SLOT(readcsv()));@
        
        1 Reply Last reply
        0
        • D Offline
          D Offline
          devfeel
          wrote on last edited by
          #23

          "qfile wont emit signals like qio":http://qt-project.org/doc/qt-4.8/qfile.html#signals

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #24

            Right ! I forgot about that.
            Did you have a look at QSocketNotifier ? It might be what you need to monitor a pipe on unix.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • D Offline
              D Offline
              devfeel
              wrote on last edited by
              #25

              thanks Sgaist
              @ notifier = new QSocketNotifier(STDIN_FILENO, QSocketNotifier::Read);
              connect(notifier, SIGNAL(activated(int)), this, SLOT(readcsv()));@

              and used repaint() function in readcsv function...now gui is showing the contents ..but gui is still freezed...
              any possible solution

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #26

                Do you still have an infinite loop somewhere ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  devfeel
                  wrote on last edited by
                  #27

                  hi sgaist...This is the code...only using while(!line.isEmpty());
                  have tried with isnull() also..but same
                  @void MainWindow::readcsv()
                  {
                  QString line;
                  //ui->alertshow->repaint();
                  qDebug()<<"in readcsv";
                  QTextStream in(stdin,QIODevice::ReadOnly);

                  do
                  {
                    // ui->alertshow->repaint();
                      qDebug()<<"inside while";
                   line = in.readLine();
                   qDebug()<<line;
                   QString delimiterPattern(",");
                   QStringList fonts = line.split(delimiterPattern);
                  
                   qDebug() <<"fonts"<< fonts;
                  
                   display(fonts);
                  
                  }while(!line.isEmpty());
                  
                  qDebug()<<"outside";
                  

                  }

                  void MainWindow::display(QStringList list)
                  {
                  ui->alertshow->repaint();
                  for(int i=0;i<list.count();i++)
                  {

                  QString li=list[i];
                  qDebug()<<"csv"<<li;
                  item=new QTableWidgetItem(li);
                  ui->alertshow->setItem(row,column,item);
                  column++;
                  }
                  // ui->alertshow->repaint();
                  }
                  @

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #28

                    Wild idea (i don't have *nix system right now at hand)

                    Why don't you do a readAll() and then parse the lines from that ?

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • clogwogC Offline
                      clogwogC Offline
                      clogwog
                      wrote on last edited by
                      #29

                      Not sure if you would be interested, but I have abit of code that starts a tail -f as a QProcess and just redirects the output of that process to a QLineEdit

                      It's not hard to do, let me know and ill lookup the snippet when I get back at work on Monday.

                      Cheers

                      1 Reply Last reply
                      0
                      • D Offline
                        D Offline
                        devfeel
                        wrote on last edited by
                        #30

                        Thanks clogwog...It would be very helpful if u provide the snippet.
                        [quote author="clogwog" date="1362136280"]Not sure if you would be interested, but I have abit of code that starts a tail -f as a QProcess and just redirects the output of that process to a QLineEdit

                        It's not hard to do, let me know and ill lookup the snippet when I get back at work on Monday.

                        Cheers[/quote]

                        1 Reply Last reply
                        0
                        • clogwogC Offline
                          clogwogC Offline
                          clogwog
                          wrote on last edited by
                          #31

                          header:

                          @myclass
                          {
                          startFollowingTail();

                          private:

                          QProcess procTail;

                          private slot:
                          void readFromStdoutForTail();
                          }@

                          in constructor:

                          @myclass::myclass() : ..... , procTail(this)
                          {
                          connect( &procTail, SIGNAL(readyReadStandardOutput()),this, SLOT(readFromStdoutForTail()) );
                          }

                          myclass::startFollowingTail()
                          {
                          if( procTail.Running)
                          procTail.kill();

                                  QStringList alist;
                                  alist << "-f" << "/tmp/software_update.log";
                                  procTail.start("/usr/bin/tail", alist, QIODevice::ReadWrite);
                          

                          }

                          void myclass::readFromStdoutForTail()
                          {
                          while ( procTail.canReadLine())
                          {
                          QByteArray a = procTail.readLine();
                          QString data = a.data();
                          ui->plainTextEdit->insertPlainText(data);
                          // scroll to end
                          ui->plainTextEdit->verticalScrollBar()->setValue(ui->plainTextEdit->verticalScrollBar()->maximum());
                          }
                          }@

                          1 Reply Last reply
                          0
                          • U Offline
                            U Offline
                            Ulatekh
                            wrote on last edited by
                            #32

                            I've only tested this on Linux (Fedora Core 16) and Qt 4.8.4, but this worked like "tail -f" for me:

                            @volatile bool shutdown = false;
                            QTextStream textStream;

                            void tailFollow()
                            {
                            while (!shutdown)
                            {
                            if (textStream.atEnd())
                            QThread::sleep (1);
                            else
                            {
                            QString line = textStream.readLine();
                            // Do something with line here...
                            }
                            }
                            }@

                            In the actual code, "shutdown" and "textStream" were member variables of a QThread subclass, and tailFollow() was a method on that QThread subclass. The client would set "shutdown" to true when the loop should exit.

                            1 Reply Last reply
                            0

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved