crossplatform.ru

Здравствуйте, гость ( Вход | Регистрация )


  Ответ в Как правильно получать вывод программы запущенной во втором потоке?
Введите ваше имя
Подтвердите код

Введите в поле код из 6 символов, отображенных в виде изображения. Если вы не можете прочитать код с изображения, нажмите на изображение для генерации нового кода.
 

Опции сообщения
 Включить смайлы?
Иконки сообщения
(Опционально)
                                
                                
  [ Без иконки ]
 


Последние 10 сообщений [ в обратном порядке ]
RazrFalcon Дата 16.8.2011, 17:01
  А если у меня несколько QProcess?
RazrFalcon Дата 2.8.2011, 14:44
  Ого! Работает.
PAFOS Дата 2.8.2011, 14:11
  Попробуй так

void OutWindow::readOut()
{
   QProcess* process = static_cast<QProcess*>(sender());
   ...
}
RazrFalcon Дата 2.8.2011, 13:30
  Нет. =/
Все что я написал, больше ничего.

Разве что там теперь:
QProcess *processing = new QProcess;
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, 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)

Вопрос: как правильно получать вывод процесса запущенного в другом потоке?
Просмотр темы полностью (откроется в новом окне)
RSS Текстовая версия Сейчас: 29.3.2024, 2:21