Помощь - Поиск - Пользователи - Календарь
Полная версия этой страницы: Как правильно получать вывод программы запущенной во втором потоке?
Форум на CrossPlatform.RU > Библиотеки > Qt > Qt Ввод/Вывод, Сеть. Межпроцессное взаимодействие
RazrFalcon
Есть:
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
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
Нет. =/
Все что я написал, больше ничего.

Разве что там теперь:
QProcess *processing = new QProcess;
PAFOS
Попробуй так

void OutWindow::readOut()
{
   QProcess* process = static_cast<QProcess*>(sender());
   ...
}
RazrFalcon
Ого! Работает.
RazrFalcon
А если у меня несколько QProcess?
Для просмотра полной версии этой страницы, пожалуйста, пройдите по ссылке.
Форум IP.Board © 2001-2024 IPS, Inc.