• 3399阅读
  • 8回复

監控 檔案的方法????????? [复制链接]

上一主题 下一主题
离线xy4301109
 
只看楼主 正序阅读 楼主  发表于: 2009-07-28
我在  /etc   建立一個 檔案
   希望 當檔案    每次被修改後 就執行text()

有人可提供一個小範本嗎?????或重點程式??
找好久  想好久  只試出 timer 可以  有其他方法嗎?? 希望是即時的
离线xy4301109
只看该作者 8楼 发表于: 2009-07-31
感謝 你的 幫忙  ~~.~~
离线shiroki

只看该作者 7楼 发表于: 2009-07-31
我找人问了一下,专家说对文件的监控得用QFileSystemWatcher, qsn对于文件不好使...
--
shiro is White
ki is tree
http://www.cuteqt.com
论坛 http://www.cuteqt.com/bbs
博客 http://www.cuteqt.com/blog
博客镜像: http://sites.cuteqt.com/cuteqt
Linux/Qt/嵌入式讨论群 http://qun.qq.com/air/5699823
离线xy4301109
只看该作者 6楼 发表于: 2009-07-31
還是 研究不出來   請大家幫幫忙
离线xy4301109
只看该作者 5楼 发表于: 2009-07-29
一直 都  試 不出來    請大家幫幫忙
有人可提供一個小範本嗎?????或重點程式??
[ 此帖被xy4301109在2009-07-30 11:19重新编辑 ]
离线xy4301109
只看该作者 4楼 发表于: 2009-07-28
#include "hello.h"
#include <qlabel.h>
#include <qtextstream.h>
#include <qfile.h>
#include <qstring.h>

HelloForm::HelloForm( QWidget* parent, const char* name, WFlags fl):
HelloBaseForm(parent, name, fl)
{
        k=0;
        PushButton2=new QPushButton(this,"PushButton1");
        PushButton2->setGeometry(QRect(50,50,50,50));
        PushButton2->setText(tr("p2"));
        connect(PushButton2,SIGNAL(clicked()),this,SLOT(text()));
        Label1=new QLabel(this,"textLabel");
        Label1->setGeometry(QRect(100,200,100,100));
        buttons_fd=open("/etc/kk",O_RDWR | O_NDELAY,0);
        QSocketNotifier *sockerNotifier= new QSocketNotifier(buttons_fd,QSocketNotifier::Write,this);
        connect(sockerNotifier,SIGNAL(activated(int)),this,SLOT(text()));
}
HelloForm::~HelloForm()
{
}
void HelloForm::text()
{
                        QString str2;
                str2=QString::number(k);
                Label1->setText(tr(str2));

        k++;
}
void HelloForm::SayHello()
{
        QString calFile="/etc/kk";
        QFile file(calFile);
        if(file.open(IO_WriteOnly | IO_Append))
        {
                QTextStream t(&file);
                t << "888";
                file.flush();
        }
}


SayHello() 是 改 文件資料   一個按鈕連結
离线shiroki

只看该作者 3楼 发表于: 2009-07-28
代码都贴出来
--
shiro is White
ki is tree
http://www.cuteqt.com
论坛 http://www.cuteqt.com/bbs
博客 http://www.cuteqt.com/blog
博客镜像: http://sites.cuteqt.com/cuteqt
Linux/Qt/嵌入式讨论群 http://qun.qq.com/air/5699823
离线xy4301109
只看该作者 2楼 发表于: 2009-07-28
        QSocketNotifier *sockerNotifier= new QSocketNotifier(pp,QSocketNotifier::Read,this);
        connect(sockerNotifier,SIGNAL(activated(int)),this,SLOT(text()));

我在text()  放進一個K++  再印出來
發現 不管檔案 是否修改   k++ 會一直跑
离线shiroki

只看该作者 1楼 发表于: 2009-07-28
用QFileSystemWatcher 或 QSocketNotifier
--
shiro is White
ki is tree
http://www.cuteqt.com
论坛 http://www.cuteqt.com/bbs
博客 http://www.cuteqt.com/blog
博客镜像: http://sites.cuteqt.com/cuteqt
Linux/Qt/嵌入式讨论群 http://qun.qq.com/air/5699823
快速回复
限100 字节
 
上一个 下一个