Версия для печати темы

Нажмите сюда для просмотра этой темы в обычном формате

Форум на CrossPlatform.RU _ Qt Ввод/Вывод, Сеть. Межпроцессное взаимодействие _ Как правильно получать вывод программы запущенной во втором потоке?

Автор: RazrFalcon 2.8.2011, 1:20

Есть:

OutWindow::OutWindow(QWidget *parent) :
    QMainWindow(parent)
{
  setupUi(this);

  QtConcurrent::run(this, &OutWindow::startCleaning);
}

void OutWindow::startCleaning()
{
  QProcess *processing;
  connect(processing,SIGNAL(readyReadStandardOutput()),this,SLOT(readOut()));
  QStringList args;
  args<<"-c"<<"../wizard/test";
  processing->start("bash",args);
  processing->waitForFinished();
}

void OutWindow::readOut()
{
  // вот здесь нужно добавить в textOutput новую строку вывода processing, то есть
  // textOutput->append(processing->readLine());
  // но processing не глобальная переменная
}

Если сделать processing глобальным, то получается что я создаю его не в во втором потоке, на что получаю:
Раскрывающийся текст
QObject: Cannot create children for a parent that is in a different thread.
(Parent is QProcess(0x885c4b8), parent's thread is QThread(0x86be250), current thread is QThread(0x8895c28)
QObject: Cannot create children for a parent that is in a different thread.
(Parent is QProcess(0x885c4b8), parent's thread is QThread(0x86be250), current thread is QThread(0x8895c28)
QObject: Cannot create children for a parent that is in a different thread.
(Parent is QProcess(0x885c4b8), parent's thread is QThread(0x86be250), current thread is QThread(0x8895c28)
QObject: Cannot create children for a parent that is in a different thread.
(Parent is QProcess(0x885c4b8), parent's thread is QThread(0x86be250), current thread is QThread(0x8895c28)
QObject: Cannot create children for a parent that is in a different thread.
(Parent is QProcess(0x885c4b8), parent's thread is QThread(0x86be250), current thread is QThread(0x8895c28)

Вопрос: как правильно получать вывод процесса запущенного в другом потоке?

Автор: wiz29 2.8.2011, 9:01

void OutWindow::startCleaning()
{
  QProcess *processing;
  connect(processing,SIGNAL(readyReadStandardOutput()),this,SLOT(readOut()));
  QStringList args;
  args<<"-c"<<"../wizard/test";
  processing->start("bash",args);
  processing->waitForFinished();
}

А где у тебя само создание или инициализация указателя processing?

Автор: RazrFalcon 2.8.2011, 13:30

Нет. =/
Все что я написал, больше ничего.

Разве что там теперь:

QProcess *processing = new QProcess;

Автор: PAFOS 2.8.2011, 14:11

Попробуй так

void OutWindow::readOut()
{
   QProcess* process = static_cast<QProcess*>(sender());
   ...
}

Автор: RazrFalcon 2.8.2011, 14:44

Ого! Работает.

Автор: RazrFalcon 16.8.2011, 17:01

А если у меня несколько QProcess?

Форум Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)