Salut.
J'ai un problème que j'ai du mal à capter.
Je créé une ihm qui li stdin dans un thread.
Normalement jusqu'ici tout va bien. D'après les recherche que j'ai faite, il n'y as pas d'autre moyen. Ça marche.
Sauf si c'est un process enfant
Si je lance cette appli dans un process enfant, la lecture du stdin bloque l'ihm, et ceci uniquement au tout début. Après ça marche nickel. Et encore plus fort, ça dépend des machine
Si quelqu'un à une idée
Qt 4.5
visual 2005

j'ai eu un problème similaire avec une appli gtk en process enfant. Qt 4.4 et visual 2005


voici un code d'exemple.Un petit chat entre process. ATTENTION il faut compiler avec le mode console :
CONFIG += console
dans le .pro

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <QtGui>
#include <iostream>
#include  	<io.h>
#include <fcntl.h>
static QString getCin()
{
    std::string s;
    std::getline(std::cin,s);
    return QString::fromStdString(s);
}
class myWidget : public QWidget
{
    Q_OBJECT
    QLineEdit * lineEdit;
    QTextBrowser * browser;
    QFutureWatcher<QString> watcher;
    QProcess myProcess;
    bool childProcess;
public:
    myWidget(bool b)
    :childProcess(b)
    {
        QVBoxLayout * l = new QVBoxLayout(this);
        lineEdit = new QLineEdit;
        browser = new QTextBrowser;
        l->addWidget(lineEdit);
        l->addWidget(browser);
        if (childProcess)
        {
            setWindowTitle("child process");
            connect(lineEdit,SIGNAL(returnPressed ()),this,SLOT(sendTostdout()));
        }
        else
        {
            setWindowTitle("parent process");
            connect(&myProcess,SIGNAL(readyReadStandardOutput ()),this,SLOT(processend()));
            connect(lineEdit,SIGNAL(returnPressed ()),this,SLOT(sendToProcess()));
            QStringList args;
            args<<"s";
            QString s = QCoreApplication::applicationFilePath () ;
            myProcess.start(QCoreApplication::applicationFilePath () ,args);
        }
 
        connect(&watcher,SIGNAL(finished ()),this,SLOT(watcherend()));
        QTimer::singleShot(0,this,SLOT(launchFuture()));
    }
 
public slots:
    void launchFuture()
    {
        watcher.setFuture(QtConcurrent::run(getCin));
    }
    void watcherend()
    {
        browser->append(watcher.result());
        watcher.setFuture(QtConcurrent::run(getCin));
    }
    void sendTostdout()
    {
        std::cout<<lineEdit->text().toStdString()<<std::endl;
        fflush(stdout);
    }
    void processend()
    {
         browser->append(myProcess.readAllStandardOutput());
    }
    void sendToProcess()
    {
        myProcess.write(lineEdit->text().toLocal8Bit());
        myProcess.putChar('\n');
    }
 
 
};
 
#include "main.moc"
int main(int argc, char **argv) {
    QApplication app(argc, argv);
    myWidget w (argc > 1);
    w.show();
    return app.exec();
}
ps : chez moi, l'ihm se bloque au premier déplacement de la fenêtre du process enfant.