小编jon*_*opf的帖子

问:当QProcess将一行写入stdout时,有没有办法发送信号

我发现了类似的问题,但从未得到确切答案.我有Qt程序启动QProcess并将输出写入QTextEdit框,到目前为止一切顺利.但只有在程序结束时才会这样做.如果可能的话,我希望程序stdout能够在真实的时间打印出来.在一个理想的世界中,当有一条线路准备好读取时,QProcess会发出某种信号,如果QProcess不可能,那么它是否可能?理想情况下,您仍然可以在进程运行时使用程序的其余部分.

继承了我到目前为止的一些代码,非常简单,它只是将QProcess标准输出的第一行发送到QTextEdit

...
extProcess::extProcess(QObject *parent) :
    QObject(parent)
    extProcess::extProcess(QObject *parent) :
    QObject(parent)
{
    proc = new QProcess(this); //initialize proc
    arguments << "-v";
    connect(proc, SIGNAL(readyRead()), this, SLOT(logReady()));

}

void extProcess::startProcess()
{
    emit clearLog();
    emit outLog("--Process started--");
    proc->start("/Users/jonathan/Desktop/testgg");
}

void extProcess::logReady()
{
       emit outLog(proc->readLine());
}
...
Run Code Online (Sandbox Code Playgroud)

这是我尝试的替代版本,这将显示整个QProcess输出,但仍然只在程序完成时显示它.

    ...
    extProcess::extProcess(QObject *parent) :
    QObject(parent)

{
    proc = new QProcess(this); //initialize proc
    proc->setProcessChannelMode(QProcess::SeparateChannels);
    arguments << "-v";
    connect(proc, SIGNAL(readyReadStandardOutput()), this, SLOT(logReady()));

}


void extProcess::logReady()
{

       while(proc->bytesAvailable()){
               emit outLog(proc->readLine());
       }
}



void extProcess::startProcess()
{
    emit clearLog();
    emit outLog("--Process …
Run Code Online (Sandbox Code Playgroud)

qt qt4

4
推荐指数
1
解决办法
2173
查看次数

python popen.stdout.readline() 挂起

我遇到了一个问题...有谁知道为什么这段代码挂在 while 循环中。循环似乎没有捕捉到stdout.

working_file = subprocess.Popen(["/pyRoot/iAmACrashyProgram"], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)

line = working_file.stdout.readline()
working_file.stdout.flush()
while working_file != "" :
    print(line)
    line = working_file.stdout.readline()
    working_file.stdout.flush()
Run Code Online (Sandbox Code Playgroud)

脚本挂起,光标在readline()遇到时会闪烁。我不明白为什么。任何人都可以透露一些信息吗?

python stdout popen

4
推荐指数
1
解决办法
1万
查看次数

如何在Sublime text 2中为语言创建新的语法hilighting集

我正在使用惊人的Sublime Text 2为Maya编写MEL(Maya嵌入式语言)脚本,但它没有MEL的语法高亮.现在我强迫它将文本解释为Perl,它做得很好,但它远非完美.添加Maya的命令会很方便.有谁知道如何为Sublime创建语法高亮设置?

syntax-highlighting mel sublimetext2

4
推荐指数
1
解决办法
6504
查看次数

jquery淡化回调而不是等待

我试图让一个div消失,然后在它的位置有第二个div淡入,但第二个div消退的回调似乎并不等待第一个完成淡入淡出,实际上它们都褪色时间给予交叉淡入效果的父亲而不是淡出然后在之后.继承人代码:

$(document).ready(function () {

    //toggle story text
    $(function () {
        $("#imageGallery").scroll(function () {

            if ($(this).scrollLeft() > 1000) {

                $("#story2").fadeIn("300", function () {
                    $("#story1").fadeOut("300");
                });


            } else {

                $("#story1").fadeIn("slow");
                $("#story2").fadeOut("slow");
            }
        });

    })

});
Run Code Online (Sandbox Code Playgroud)

和页面即时使用它:

http://www.jonathantopf.com/imijstudio/

任何想法为什么会这样?

jquery callback fadein

3
推荐指数
1
解决办法
6629
查看次数

最佳实践 - 什么是观看目录的最佳方式

我需要设置一个脚本来监视某个类型的文件的文件夹.我做了这个代码,但我想知道是否有更好的方法?

import os


def listAppleseedFiles(directory_path):
    directory_entities =  os.listdir(directory_path)
    files = []
    appleseed_files = []
    for entity in directory_entities:
        file_path = os.path.join(directory_path, entity)
        if os.path.isfile(file_path):
            if os.path.splitext(file_path)[1] == '.appleseed':
                appleseed_files.append(file_path)

    return appleseed_files

while True:
    for file in listAppleseedFiles('/dir_name'):

        doSomething()
Run Code Online (Sandbox Code Playgroud)

python directory watch

3
推荐指数
1
解决办法
264
查看次数

如何将路径字符串的格式更改为不同的操作系统?

我需要将文件路径从 MAC 更改为 Windows,我正准备做一个简单.replace()的任何操作/\但我突然想到可能有更好的方法。所以例如我需要改变:

foo/bar/file.txt
Run Code Online (Sandbox Code Playgroud)

到:

foo\bar\file.txt
Run Code Online (Sandbox Code Playgroud)

python operating-system path

3
推荐指数
2
解决办法
6714
查看次数

有没有办法在QSlider值增加时生成信号

我试图从QSlider触发一个明显的信号,以了解它的增大或减小。不幸的是,由于程序的限制,我无法在控件范围内创建,因此无法跟踪滑块的值,只能进行比较。

有没有办法做到这一点?

qt slider signals-slots

2
推荐指数
1
解决办法
1120
查看次数

类变量在JavaScript中返回undefined

我是JavaScript的新手.因此这个问题有点令人困惑.我试图简单地定义一个计数器并在类方法中增加它,但它的行为不像我期望的那样.专门console.log(this.tick_count);打印undefined.

JavaScript的:

function Game() {
    this.fps = 50;
    this.ticks = 3;
    this.current_time = (new Date).getTime();
    this.draw_object = document.getElementById('game_canvas').getContext('2d');
    this.tick_count = 0;
}

Game.prototype.update = function (time) {
    this.current_time = time;
}

Game.prototype.draw = function () {
    this.draw_object.fillRect(10, 10, 55, 50);
}

Game.prototype.run = function () {
    self.setInterval(this.tick, 1000 / (this.fps * this.tick));
}

Game.prototype.tick = function () {
    this.tick_count++;
    console.log(this.tick_count);
}

function start_game() {
    var game_object = new Game();
    game_object.run();
}
Run Code Online (Sandbox Code Playgroud)

HTML:

<body onload="start_game()">
    <canvas id="game_canvas" …
Run Code Online (Sandbox Code Playgroud)

javascript variables class

2
推荐指数
1
解决办法
5104
查看次数

pymongo无法连接到远程服务器上的数据库

我已经设置了一个在外部主机服务器上运行的mongodb服务器,我可以通过在客户端计算机shell中执行以下操作来轻松连接mongo客户端:

162.243.27.34 --port 27017
Run Code Online (Sandbox Code Playgroud)

但是当我尝试使用python使用pymongo连接到服务器时,我得到以下输出

import pymongo
client = pymongo.MongoClient('162.243.27.34', 27017)
Run Code Online (Sandbox Code Playgroud)

错误

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/pymongo/mongo_client.py", line 352, in __init__
    raise ConnectionFailure(str(e))
pymongo.errors.ConnectionFailure: could not connect to 162.243.27.34:27017: [Errno 111] Connection refused
Run Code Online (Sandbox Code Playgroud)

我在这做错了什么?

更新 - 更多信息

IP 162.243.27.34上的数据库服务器和客户端是具有不同IP的单独服务器.在上述示例中,在两种情况下,我都尝试从远程客户端服务器进行连接,而不是连接到"localhost".

数据库服务器上有防火墙,但客户端确实有访问权限,并且mongo客户端命令行程序从客户端服务器连接正常我假设从客户端连接到数据库服务器没有网络问题,而是我如何使用python进行连接存在问题.

更新2

运行命令:

cat /etc/mongodb.conf
Run Code Online (Sandbox Code Playgroud)

说明:

bind_ip = 127.0.0.1
#port = 27017
Run Code Online (Sandbox Code Playgroud)

我也使用MongoDB shell版本:2.0.4

mongodb pymongo

2
推荐指数
1
解决办法
4475
查看次数

init 让属性在 swift 的子类中引用 self

我学得很快,经常遇到以下问题。我将有一个带有属性的类,感觉它应该是一个let属性,因为它只会被设置一次。我还希望这个子对象维护对其所有者的引用,该所有者也应该是一个let属性,因为父关系不会改变。let当父类子类化另一个类并且所有属性都需要在运行之前设置super.init ()但需要引用selfinit 时,就会出现问题。

这是一个简单的例子

class NodeView: UIView {
    let _nodePlugView: NodePlugView

    init (node: Node) {
        _nodePlugView = NodePlugView (parentView: self)
        super.init ()
    }
}
Run Code Online (Sandbox Code Playgroud)

当然,我可以只用var这些_nodePlugView,但感觉不太合适。人们会推荐另一种模式吗?

swift

2
推荐指数
1
解决办法
1724
查看次数