class CArmProject : public QObject{ Q_OBJECT CSoundServer * fsoundServer; //обертка над фононом QThread fsoundThread; //поток в который хочу перенетсти звук}CArmProject::CArmProject(QMainWindow * mainWindow): QObject(NULL){ fsoundServer = new CSoundServer; //создаю звуковой сервак в куче без родителя fsoundServer->moveToThread(&fsoundThread); //перевожу его в поток fsoundThread.start(); //запускаю поток}ArmProject::~CArmProject(){ if(fsoundThread.isRunning()) { fsoundThread.quit(); fsoundThread.wait(); } fsoundServer->deleteLater();}
void CArmProject::relinkAlerts(){ foreach(CGenericRailObjectStorage * currentStorage, fstorageMap->values()) //проходимся по всем ЭЦ в проекте { foreach (CRailObjectProvider * currentProvider, currentStorage->providers().values()) //проходимся по всем провайдерам { foreach (CRailObject * currentObject, currentProvider->objects().values()) //и по всем объектам каждого провайдера { connect(currentObject,SIGNAL(soundAlert(const QString &)),fsoundServer,SLOT(playAlert(const QString &))); } } }}
class CSoundServer : public QObject{ Q_OBJECT Phonon::MediaObject * mediaObject; Phonon::AudioOutput * audioOutput; //устройсто вывода звука QString ffilePath; //путь к звуковым файлам QHash<QString,QString> falertLinkToFileHash; //хеш ссылок objectId:alertRole -> fileNamepublic: explicit CSoundServer(QObject *parent = 0); ~CSoundServer(); void setAlerts(CGenericRailObjectStorageMap *storageMap, const CSoundAlertItemList & alerts); const QString & filePath() const;public slots: void playFile(const QString & fileName); void playAlert(const QString & alertRole); //проиграть алерт void clear();};
void CSoundServer::playFile(const QString & fileName){ mediaObject->setCurrentSource(Phonon::MediaSource(filePath()+"/"+fileName)); mediaObject->play();}void CSoundServer::playAlert(const QString &alertRole){ CRailObject * railObject = qobject_cast<CRailObject*>(sender()); if(railObject) { QString linkId = linkTemplate.arg(railObject->parentStorage()->id()).arg(railObject->objectId()).arg(alertRole); QString fileName = falertLinkToFileHash.value(linkId); //qDebug("alert: %s",qPrintable(linkId)); if(!fileName.isEmpty()) { playFile(fileName); } }}
QObject: Cannot create children for a parent that is in a different thread.(Parent is QApplication(0x7fff6df795c0), parent's thread is QThread(0x1939d40), current thread is QThread(0x1b36de0)QObject: Cannot create children for a parent that is in a different thread.(Parent is QApplication(0x7fff6df795c0), parent's thread is QThread(0x1939d40), current thread is QThread(0x1b36de0)QObject: Cannot create children for a parent that is in a different thread.(Parent is QApplication(0x7fff6df795c0), parent's thread is QThread(0x1939d40), current thread is QThread(0x1b36de0)QObject: Cannot create children for a parent that is in a different thread.(Parent is QApplication(0x7fff6df795c0), parent's thread is QThread(0x1939d40), current thread is QThread(0x1b36de0)QObject: Cannot create children for a parent that is in a different thread.(Parent is QApplication(0x7fff6df795c0), parent's thread is QThread(0x1939d40), current thread is QThread(0x1b36de0)QObject: Cannot create children for a parent that is in a different thread.(Parent is QApplication(0x7fff6df795c0), parent's thread is QThread(0x1939d40), current thread is QThread(0x1b36de0)QObject: Cannot create children for a parent that is in a different thread.(Parent is QApplication(0x7fff6df795c0), parent's thread is QThread(0x1939d40), current thread is QThread(0x1b36de0)QObject: Cannot create children for a parent that is in a different thread.(Parent is QApplication(0x7fff6df795c0), parent's thread is QThread(0x1939d40), current thread is QThread(0x1b36de0)QObject: Cannot create children for a parent that is in a different thread.(Parent is QApplication(0x7fff6df795c0), parent's thread is QThread(0x1939d40), current thread is QThread(0x1b36de0)QObject: Cannot create children for a parent that is in a different thread.(Parent is QApplication(0x7fff6df795c0), parent's thread is QThread(0x1939d40), current thread is QThread(0x1b36de0)QObject: Cannot create children for a parent that is in a different thread.(Parent is QApplication(0x7fff6df795c0), parent's thread is QThread(0x1939d40), current thread is QThread(0x1b36de0)QObject: Cannot create children for a parent that is in a different thread.(Parent is QApplication(0x7fff6df795c0), parent's thread is QThread(0x1939d40), current thread is QThread(0x1b36de0)QObject: Cannot create children for a parent that is in a different thread.(Parent is QApplication(0x7fff6df795c0), parent's thread is QThread(0x1939d40), current thread is QThread(0x1b36de0)QObject: Cannot create children for a parent that is in a different thread.(Parent is QApplication(0x7fff6df795c0), parent's thread is QThread(0x1939d40), current thread is QThread(0x1b36de0)QObject: Cannot create children for a parent that is in a different thread.(Parent is QApplication(0x7fff6df795c0), parent's thread is QThread(0x1939d40), current thread is QThread(0x1b36de0)QObject: Cannot create children for a parent that is in a different thread.(Parent is QApplication(0x7fff6df795c0), parent's thread is QThread(0x1939d40), current thread is QThread(0x1b36de0)QObject: Cannot create children for a parent that is in a different thread.(Parent is QApplication(0x7fff6df795c0), parent's thread is QThread(0x1939d40), current thread is QThread(0x1b36de0)QObject: Cannot create children for a parent that is in a different thread.(Parent is QApplication(0x7fff6df795c0), parent's thread is QThread(0x1939d40), current thread is QThread(0x1b36de0)QObject: Cannot create children for a parent that is in a different thread.(Parent is QApplication(0x7fff6df795c0), parent's thread is QThread(0x1939d40), current thread is QThread(0x1b36de0)QObject: Cannot create children for a parent that is in a different thread.(Parent is QApplication(0x7fff6df795c0), parent's thread is QThread(0x1939d40), current thread is QThread(0x1b36de0)QObject: Cannot create children for a parent that is in a different thread.(Parent is QApplication(0x7fff6df795c0), parent's thread is QThread(0x1939d40), current thread is QThread(0x1b36de0)QObject: Cannot create children for a parent that is in a different thread.(Parent is QApplication(0x7fff6df795c0), parent's thread is QThread(0x1939d40), current thread is QThread(0x7f135400d500)QObject: Cannot create children for a parent that is in a different thread.(Parent is QApplication(0x7fff6df795c0), parent's thread is QThread(0x1939d40), current thread is QThread(0x1b36de0)QObject: Cannot create children for a parent that is in a different thread.(Parent is QApplication(0x7fff6df795c0), parent's thread is QThread(0x1939d40), current thread is QThread(0x1b36de0)QObject: Cannot create children for a parent that is in a different thread.(Parent is QApplication(0x7fff6df795c0), parent's thread is QThread(0x1939d40), current thread is QThread(0x1b36de0)QObject: Cannot create children for a parent that is in a different thread.(Parent is QApplication(0x7fff6df795c0), parent's thread is QThread(0x1939d40), current thread is QThread(0x1b36de0)QObject: Cannot create children for a parent that is in a different thread.(Parent is QApplication(0x7fff6df795c0), parent's thread is QThread(0x1939d40), current thread is QThread(0x1b36de0)QObject: Cannot create children for a parent that is in a different thread.(Parent is QApplication(0x7fff6df795c0), parent's thread is QThread(0x1939d40), current thread is QThread(0x1b36de0)QObject: Cannot create children for a parent that is in a different thread.(Parent is QApplication(0x7fff6df795c0), parent's thread is QThread(0x1939d40), current thread is QThread(0x7f135400d500)QObject: Cannot create children for a parent that is in a different thread.(Parent is QApplication(0x7fff6df795c0), parent's thread is QThread(0x1939d40), current thread is QThread(0x7f135400d500)QObject: Cannot create children for a parent that is in a different thread.(Parent is QApplication(0x7fff6df795c0), parent's thread is QThread(0x1939d40), current thread is QThread(0x1b36de0)QObject: Cannot create children for a parent that is in a different thread.(Parent is QApplication(0x7fff6df795c0), parent's thread is QThread(0x1939d40), current thread is QThread(0x1b36de0)QObject: Cannot create children for a parent that is in a different thread.(Parent is QApplication(0x7fff6df795c0), parent's thread is QThread(0x1939d40), current thread is QThread(0x1b36de0)QObject: Cannot create children for a parent that is in a different thread.(Parent is QApplication(0x7fff6df795c0), parent's thread is QThread(0x1939d40), current thread is QThread(0x1b36de0)QObject: Cannot create children for a parent that is in a different thread.(Parent is QApplication(0x7fff6df795c0), parent's thread is QThread(0x1939d40), current thread is QThread(0x1b36de0)QObject: Cannot create children for a parent that is in a different thread.(Parent is QApplication(0x7fff6df795c0), parent's thread is QThread(0x1939d40), current thread is QThread(0x1b36de0)QObject: Cannot create children for a parent that is in a different thread.(Parent is QApplication(0x7fff6df795c0), parent's thread is QThread(0x1939d40), current thread is QThread(0x1b36de0)QObject: Cannot create children for a parent that is in a different thread.(Parent is QApplication(0x7fff6df795c0), parent's thread is QThread(0x1939d40), current thread is QThread(0x1b36de0)QObject: Cannot create children for a parent that is in a different thread.(Parent is QApplication(0x7fff6df795c0), parent's thread is QThread(0x1939d40), current thread is QThread(0x1b36de0)QObject: Cannot create children for a parent that is in a different thread.(Parent is QApplication(0x7fff6df795c0), parent's thread is QThread(0x1939d40), current thread is QThread(0x1b36de0)QObject: Cannot create children for a parent that is in a different thread.(Parent is QApplication(0x7fff6df795c0), parent's thread is QThread(0x1939d40), current thread is QThread(0x1b36de0)QObject: Cannot create children for a parent that is in a different thread.(Parent is QApplication(0x7fff6df795c0), parent's thread is QThread(0x1939d40), current thread is QThread(0x1b36de0)