本文整理汇总了C++中QThread::setObjectName方法的典型用法代码示例。如果您正苦于以下问题:C++ QThread::setObjectName方法的具体用法?C++ QThread::setObjectName怎么用?C++ QThread::setObjectName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QThread
的用法示例。
在下文中一共展示了QThread::setObjectName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QTcpServer
Servatrice_GameServer::Servatrice_GameServer(Servatrice *_server, int _numberPools, const QSqlDatabase &_sqlDatabase, QObject *parent)
: QTcpServer(parent),
server(_server)
{
if (_numberPools == 0) {
server->setThreaded(false);
Servatrice_DatabaseInterface *newDatabaseInterface = new Servatrice_DatabaseInterface(0, server);
Servatrice_ConnectionPool *newPool = new Servatrice_ConnectionPool(newDatabaseInterface);
server->addDatabaseInterface(thread(), newDatabaseInterface);
newDatabaseInterface->initDatabase(_sqlDatabase);
connectionPools.append(newPool);
} else
for (int i = 0; i < _numberPools; ++i) {
Servatrice_DatabaseInterface *newDatabaseInterface = new Servatrice_DatabaseInterface(i, server);
Servatrice_ConnectionPool *newPool = new Servatrice_ConnectionPool(newDatabaseInterface);
QThread *newThread = new QThread;
newThread->setObjectName("pool_" + QString::number(i));
newPool->moveToThread(newThread);
newDatabaseInterface->moveToThread(newThread);
server->addDatabaseInterface(newThread, newDatabaseInterface);
newThread->start();
QMetaObject::invokeMethod(newDatabaseInterface, "initDatabase", Qt::BlockingQueuedConnection, Q_ARG(QSqlDatabase, _sqlDatabase));
connectionPools.append(newPool);
}
}
示例2: init
// Sets up the settings private instance. Should only be run once at startup
void init() {
// read the ApplicationInfo.ini file for Name/Version/Domain information
QSettings::setDefaultFormat(QSettings::IniFormat);
QSettings applicationInfo(PathUtils::resourcesPath() + "info/ApplicationInfo.ini", QSettings::IniFormat);
// set the associated application properties
applicationInfo.beginGroup("INFO");
QCoreApplication::setApplicationName(applicationInfo.value("name").toString());
QCoreApplication::setOrganizationName(applicationInfo.value("organizationName").toString());
QCoreApplication::setOrganizationDomain(applicationInfo.value("organizationDomain").toString());
// Let's set up the settings Private instance on it's own thread
QThread* thread = new QThread();
Q_CHECK_PTR(thread);
thread->setObjectName("Settings Thread");
privateInstance = new Manager();
Q_CHECK_PTR(privateInstance);
QObject::connect(privateInstance, SIGNAL(destroyed()), thread, SLOT(quit()));
QObject::connect(thread, SIGNAL(started()), privateInstance, SLOT(startTimer()));
QObject::connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
privateInstance->moveToThread(thread);
thread->start();
qCDebug(shared) << "Settings thread started.";
// Register cleanupPrivateInstance to run inside QCoreApplication's destructor.
qAddPostRoutine(cleanupPrivateInstance);
}
示例3: handleCreateAssignmentPacket
void AssignmentClient::handleCreateAssignmentPacket(QSharedPointer<ReceivedMessage> message) {
qCDebug(assigmnentclient) << "Received a PacketType::CreateAssignment - attempting to unpack.";
if (_currentAssignment) {
qCWarning(assigmnentclient) << "Received a PacketType::CreateAssignment while still running an active assignment. Ignoring.";
return;
}
// construct the deployed assignment from the packet data
_currentAssignment = AssignmentFactory::unpackAssignment(*message);
if (_currentAssignment && !_isAssigned) {
qDebug(assigmnentclient) << "Received an assignment -" << *_currentAssignment;
_isAssigned = true;
auto nodeList = DependencyManager::get<NodeList>();
// switch our DomainHandler hostname and port to whoever sent us the assignment
nodeList->getDomainHandler().setSockAddr(message->getSenderSockAddr(), _assignmentServerHostname);
nodeList->getDomainHandler().setAssignmentUUID(_currentAssignment->getUUID());
qCDebug(assigmnentclient) << "Destination IP for assignment is" << nodeList->getDomainHandler().getIP().toString();
// start the deployed assignment
QThread* workerThread = new QThread;
workerThread->setObjectName("ThreadedAssignment Worker");
connect(workerThread, &QThread::started, _currentAssignment.data(), &ThreadedAssignment::run);
// Once the ThreadedAssignment says it is finished - we ask it to deleteLater
// This is a queued connection so that it is put into the event loop to be processed by the worker
// thread when it is ready.
connect(_currentAssignment.data(), &ThreadedAssignment::finished, _currentAssignment.data(),
&ThreadedAssignment::deleteLater, Qt::QueuedConnection);
// once it is deleted, we quit the worker thread
connect(_currentAssignment.data(), &ThreadedAssignment::destroyed, workerThread, &QThread::quit);
// have the worker thread remove itself once it is done
connect(workerThread, &QThread::finished, workerThread, &QThread::deleteLater);
// once the worker thread says it is done, we consider the assignment completed
connect(workerThread, &QThread::destroyed, this, &AssignmentClient::assignmentCompleted);
_currentAssignment->moveToThread(workerThread);
// Starts an event loop, and emits workerThread->started()
workerThread->start();
} else {
qCWarning(assigmnentclient) << "Received an assignment that could not be unpacked. Re-requesting.";
}
}
示例4: slotRender
void cThumbnailWidget::slotRender()
{
if (image && params)
{
stopRequest = true;
while (image->IsUsed())
{
// just wait and pray
Wait(100);
}
// random wait to not generate to many events at exactly the same time
Wait(Random(100) + 50);
if (cRenderJob::GetRunningJobCount() > systemData.numberOfThreads)
{
// try again after some random time
timer->start(Random(5000) + 1);
return;
}
stopRequest = false;
cRenderJob *renderJob =
new cRenderJob(params, fractal, image, &stopRequest, static_cast<QWidget *>(this));
connect(renderJob, SIGNAL(updateProgressAndStatus(const QString &, const QString &, double)),
this, SIGNAL(updateProgressAndStatus(const QString &, const QString &, double)));
connect(renderJob, SIGNAL(updateImage()), this, SLOT(update()));
renderingTimeTimer.start();
renderJob->UseSizeFromImage(true);
cRenderingConfiguration config;
if (useOneCPUCore) config.DisableMultiThread();
config.EnableIgnoreErrors();
config.DisableNetRender();
renderJob->Init(cRenderJob::still, config);
QThread *thread = new QThread;
renderJob->moveToThread(thread);
QObject::connect(thread, SIGNAL(started()), renderJob, SLOT(slotExecute()));
thread->setObjectName("ThumbnailWorker");
thread->start();
QObject::connect(renderJob, SIGNAL(finished()), renderJob, SLOT(deleteLater()));
QObject::connect(renderJob, SIGNAL(finished()), thread, SLOT(quit()));
QObject::connect(renderJob, SIGNAL(fullyRendered(const QString &, const QString &)), this,
SLOT(slotFullyRendered()));
QObject::connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
}
示例5: playSound
AudioInjector* AudioInjector::playSound(const QByteArray& buffer, const AudioInjectorOptions options, AbstractAudioInterface* localInterface) {
QThread* injectorThread = new QThread();
injectorThread->setObjectName("Audio Injector Thread");
AudioInjector* injector = new AudioInjector(buffer, options);
injector->setLocalAudioInterface(localInterface);
injector->moveToThread(injectorThread);
// start injecting when the injector thread starts
connect(injectorThread, &QThread::started, injector, &AudioInjector::injectAudio);
// connect the right slots and signals for AudioInjector and thread cleanup
connect(injector, &AudioInjector::destroyed, injectorThread, &QThread::quit);
connect(injectorThread, &QThread::finished, injectorThread, &QThread::deleteLater);
injectorThread->start();
return injector;
}
示例6: enterEventLoop
void CmaClient::enterEventLoop(vita_device_t *device)
{
vita_event_t event;
qDebug("Starting event loop");
CmaEvent eventLoop (device);
QThread thread;
thread.setObjectName("event_thread");
eventLoop.moveToThread(&thread);
connect(&thread, SIGNAL(started()), &eventLoop, SLOT(process()));
connect(&eventLoop, SIGNAL(refreshDatabase()), this, SIGNAL(refreshDatabase()), Qt::DirectConnection);
connect(&eventLoop, SIGNAL(finishedEventLoop()), &thread, SLOT(quit()), Qt::DirectConnection);
thread.start();
while(isActive()) {
if(VitaMTP_Read_Event(device, &event) < 0) {
qWarning("Error reading event from Vita.");
break;
}
// do not create a event for this since there aren't more events to read
if(event.Code == PTP_EC_VITA_RequestTerminate) {
qDebug("Terminating event thread");
break;
// this one shuold be processed inmediately
} else if(event.Code == PTP_EC_VITA_RequestCancelTask) {
eventLoop.vitaEventCancelTask(&event, event.Param1);
qDebug("Ended event, code: 0x%x, id: %d", event.Code, event.Param1);
continue;
}
// the events are processed synchronously except for cancel/terminate
qDebug("Sending new event");
eventLoop.setEvent(event);
}
eventLoop.stop();
thread.wait();
qDebug("Finishing event loop");
}
示例7: start
/**
* @brief start initializes the Host Cache.
* Make sure this is not called before QApplication is instantiated.
* Any custom initializations should be made within asyncStartUpHelper().
* Locking: YES (asynchronous)
*/
void HostCache::start()
{
#if ENABLE_G2_HOST_CACHE_DEBUGGING
systemLog.postLog( LogSeverity::Debug, Component::HostCache, QString( "start()" ) );
#endif //ENABLE_G2_HOST_CACHE_DEBUGGING
QThread* pThread = new QThread();
// set thread name
pThread->setObjectName( "Host Cache and Discovery" );
moveToThread( pThread );
pThread->start( QThread::LowPriority );
// Handle destruction gracefully.
connect( pThread, &QThread::finished, pThread, &QObject::deleteLater );
m_pHostCacheDiscoveryThread = pThread;
QMetaObject::invokeMethod( this, "startUpInternal", Qt::BlockingQueuedConnection );
}
示例8: SendQueue
std::unique_ptr<SendQueue> SendQueue::create(Socket* socket, HifiSockAddr destination) {
Q_ASSERT_X(socket, "SendQueue::create", "Must be called with a valid Socket*");
auto queue = std::unique_ptr<SendQueue>(new SendQueue(socket, destination));
// Setup queue private thread
QThread* thread = new QThread;
thread->setObjectName("Networking: SendQueue " + destination.objectName()); // Name thread for easier debug
connect(thread, &QThread::started, queue.get(), &SendQueue::run);
connect(queue.get(), &QObject::destroyed, thread, &QThread::quit); // Thread auto cleanup
connect(thread, &QThread::finished, thread, &QThread::deleteLater); // Thread auto cleanup
// Move queue to private thread and start it
queue->moveToThread(thread);
thread->start();
return queue;
}
示例9: run
void Agent::run() {
// make sure we request our script once the agent connects to the domain
auto nodeList = DependencyManager::get<NodeList>();
connect(&nodeList->getDomainHandler(), &DomainHandler::connectedToDomain, this, &Agent::requestScript);
ThreadedAssignment::commonInit(AGENT_LOGGING_NAME, NodeType::Agent);
// Setup MessagesClient
auto messagesClient = DependencyManager::set<MessagesClient>();
QThread* messagesThread = new QThread;
messagesThread->setObjectName("Messages Client Thread");
messagesClient->moveToThread(messagesThread);
connect(messagesThread, &QThread::started, messagesClient.data(), &MessagesClient::init);
messagesThread->start();
nodeList->addSetOfNodeTypesToNodeInterestSet({
NodeType::AudioMixer, NodeType::AvatarMixer, NodeType::EntityServer, NodeType::MessagesMixer, NodeType::AssetServer
});
}
示例10: ThreadedAssignment
Agent::Agent(ReceivedMessage& message) :
ThreadedAssignment(message),
_entityEditSender(),
_receivedAudioStream(AudioConstants::NETWORK_FRAME_SAMPLES_STEREO, RECEIVED_AUDIO_STREAM_CAPACITY_FRAMES,
InboundAudioStream::Settings(0, false, RECEIVED_AUDIO_STREAM_CAPACITY_FRAMES, false,
DEFAULT_WINDOW_STARVE_THRESHOLD, DEFAULT_WINDOW_SECONDS_FOR_DESIRED_CALC_ON_TOO_MANY_STARVES,
DEFAULT_WINDOW_SECONDS_FOR_DESIRED_REDUCTION, false))
{
DependencyManager::get<EntityScriptingInterface>()->setPacketSender(&_entityEditSender);
auto assetClient = DependencyManager::set<AssetClient>();
QThread* assetThread = new QThread;
assetThread->setObjectName("Asset Thread");
assetClient->moveToThread(assetThread);
connect(assetThread, &QThread::started, assetClient.data(), &AssetClient::init);
assetThread->start();
DependencyManager::registerInheritance<SpatialParentFinder, AssignmentParentFinder>();
DependencyManager::set<ResourceCacheSharedItems>();
DependencyManager::set<SoundCache>();
DependencyManager::set<AudioInjectorManager>();
DependencyManager::set<recording::Deck>();
DependencyManager::set<recording::Recorder>();
DependencyManager::set<RecordingScriptingInterface>();
auto& packetReceiver = DependencyManager::get<NodeList>()->getPacketReceiver();
packetReceiver.registerListenerForTypes(
{ PacketType::MixedAudio, PacketType::SilentAudioFrame },
this, "handleAudioPacket");
packetReceiver.registerListenerForTypes(
{ PacketType::OctreeStats, PacketType::EntityData, PacketType::EntityErase },
this, "handleOctreePacket");
packetReceiver.registerListener(PacketType::Jurisdiction, this, "handleJurisdictionPacket");
}
示例11: initServer
//.........这里部分代码省略.........
}
settings->endArray();
}
updateLoginMessage();
maxGameInactivityTime = settings->value("game/max_game_inactivity_time").toInt();
maxPlayerInactivityTime = settings->value("game/max_player_inactivity_time").toInt();
maxUsersPerAddress = settings->value("security/max_users_per_address").toInt();
messageCountingInterval = settings->value("security/message_counting_interval").toInt();
maxMessageCountPerInterval = settings->value("security/max_message_count_per_interval").toInt();
maxMessageSizePerInterval = settings->value("security/max_message_size_per_interval").toInt();
maxGamesPerUser = settings->value("security/max_games_per_user").toInt();
try { if (settings->value("servernetwork/active", 0).toInt()) {
qDebug() << "Connecting to ISL network.";
const QString certFileName = settings->value("servernetwork/ssl_cert").toString();
const QString keyFileName = settings->value("servernetwork/ssl_key").toString();
qDebug() << "Loading certificate...";
QFile certFile(certFileName);
if (!certFile.open(QIODevice::ReadOnly))
throw QString("Error opening certificate file: %1").arg(certFileName);
QSslCertificate cert(&certFile);
#if QT_VERSION < 0x050000
if (!cert.isValid())
throw(QString("Invalid certificate."));
#else
const QDateTime currentTime = QDateTime::currentDateTime();
if(currentTime < cert.effectiveDate() ||
currentTime > cert.expiryDate() ||
cert.isBlacklisted())
throw(QString("Invalid certificate."));
#endif
qDebug() << "Loading private key...";
QFile keyFile(keyFileName);
if (!keyFile.open(QIODevice::ReadOnly))
throw QString("Error opening private key file: %1").arg(keyFileName);
QSslKey key(&keyFile, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey);
if (key.isNull())
throw QString("Invalid private key.");
QMutableListIterator<ServerProperties> serverIterator(serverList);
while (serverIterator.hasNext()) {
const ServerProperties &prop = serverIterator.next();
if (prop.cert == cert) {
serverIterator.remove();
continue;
}
QThread *thread = new QThread;
thread->setObjectName("isl_" + QString::number(prop.id));
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
IslInterface *interface = new IslInterface(prop.id, prop.hostname, prop.address.toString(), prop.controlPort, prop.cert, cert, key, this);
interface->moveToThread(thread);
connect(interface, SIGNAL(destroyed()), thread, SLOT(quit()));
thread->start();
QMetaObject::invokeMethod(interface, "initClient", Qt::BlockingQueuedConnection);
}
const int networkPort = settings->value("servernetwork/port", 14747).toInt();
qDebug() << "Starting ISL server on port" << networkPort;
islServer = new Servatrice_IslServer(this, cert, key, this);
if (islServer->listen(QHostAddress::Any, networkPort))
qDebug() << "ISL server listening.";
else
throw QString("islServer->listen()");
} } catch (QString error) {
qDebug() << "ERROR --" << error;
return false;
}
pingClock = new QTimer(this);
connect(pingClock, SIGNAL(timeout()), this, SIGNAL(pingClockTimeout()));
pingClock->start(1000);
int statusUpdateTime = settings->value("server/statusupdate").toInt();
statusUpdateClock = new QTimer(this);
connect(statusUpdateClock, SIGNAL(timeout()), this, SLOT(statusUpdate()));
if (statusUpdateTime != 0) {
qDebug() << "Starting status update clock, interval " << statusUpdateTime << " ms";
statusUpdateClock->start(statusUpdateTime);
}
const int numberPools = settings->value("server/number_pools", 1).toInt();
gameServer = new Servatrice_GameServer(this, numberPools, servatriceDatabaseInterface->getDatabase(), this);
gameServer->setMaxPendingConnections(1000);
const int gamePort = settings->value("server/port", 4747).toInt();
qDebug() << "Starting server on port" << gamePort;
if (gameServer->listen(QHostAddress::Any, gamePort))
qDebug() << "Server listening.";
else {
qDebug() << "gameServer->listen(): Error.";
return false;
}
return true;
}
示例12: QThread
AssignmentClient::AssignmentClient(Assignment::Type requestAssignmentType, QString assignmentPool,
quint16 listenPort, QUuid walletUUID, QString assignmentServerHostname,
quint16 assignmentServerPort, quint16 assignmentMonitorPort) :
_assignmentServerHostname(DEFAULT_ASSIGNMENT_SERVER_HOSTNAME)
{
LogUtils::init();
QSettings::setDefaultFormat(QSettings::IniFormat);
DependencyManager::set<AccountManager>();
auto scriptableAvatar = DependencyManager::set<ScriptableAvatar>();
auto addressManager = DependencyManager::set<AddressManager>();
auto scriptEngines = DependencyManager::set<ScriptEngines>();
// create a NodeList as an unassigned client, must be after addressManager
auto nodeList = DependencyManager::set<NodeList>(NodeType::Unassigned, listenPort);
auto animationCache = DependencyManager::set<AnimationCache>();
auto entityScriptingInterface = DependencyManager::set<EntityScriptingInterface>(false);
DependencyManager::registerInheritance<EntityActionFactoryInterface, AssignmentActionFactory>();
auto actionFactory = DependencyManager::set<AssignmentActionFactory>();
DependencyManager::set<ResourceScriptingInterface>();
// setup a thread for the NodeList and its PacketReceiver
QThread* nodeThread = new QThread(this);
nodeThread->setObjectName("NodeList Thread");
nodeThread->start();
// make sure the node thread is given highest priority
nodeThread->setPriority(QThread::TimeCriticalPriority);
// put the NodeList on the node thread
nodeList->moveToThread(nodeThread);
// set the logging target to the the CHILD_TARGET_NAME
LogHandler::getInstance().setTargetName(ASSIGNMENT_CLIENT_TARGET_NAME);
// make sure we output process IDs for a child AC otherwise it's insane to parse
LogHandler::getInstance().setShouldOutputProcessID(true);
// setup our _requestAssignment member variable from the passed arguments
_requestAssignment = Assignment(Assignment::RequestCommand, requestAssignmentType, assignmentPool);
// check for a wallet UUID on the command line or in the config
// this would represent where the user running AC wants funds sent to
if (!walletUUID.isNull()) {
qCDebug(assigmnentclient) << "The destination wallet UUID for credits is" << uuidStringWithoutCurlyBraces(walletUUID);
_requestAssignment.setWalletUUID(walletUUID);
}
// check for an overriden assignment server hostname
if (assignmentServerHostname != "") {
// change the hostname for our assignment server
_assignmentServerHostname = assignmentServerHostname;
}
_assignmentServerSocket = HifiSockAddr(_assignmentServerHostname, assignmentServerPort, true);
_assignmentServerSocket.setObjectName("AssigmentServer");
nodeList->setAssignmentServerSocket(_assignmentServerSocket);
qCDebug(assigmnentclient) << "Assignment server socket is" << _assignmentServerSocket;
// call a timer function every ASSIGNMENT_REQUEST_INTERVAL_MSECS to ask for assignment, if required
qCDebug(assigmnentclient) << "Waiting for assignment -" << _requestAssignment;
if (_assignmentServerHostname != "localhost") {
qCDebug(assigmnentclient) << "- will attempt to connect to domain-server on" << _assignmentServerSocket.getPort();
}
connect(&_requestTimer, SIGNAL(timeout()), SLOT(sendAssignmentRequest()));
_requestTimer.start(ASSIGNMENT_REQUEST_INTERVAL_MSECS);
// connections to AccountManager for authentication
connect(DependencyManager::get<AccountManager>().data(), &AccountManager::authRequired,
this, &AssignmentClient::handleAuthenticationRequest);
// Create Singleton objects on main thread
NetworkAccessManager::getInstance();
// did we get an assignment-client monitor port?
if (assignmentMonitorPort > 0) {
_assignmentClientMonitorSocket = HifiSockAddr(DEFAULT_ASSIGNMENT_CLIENT_MONITOR_HOSTNAME, assignmentMonitorPort);
_assignmentClientMonitorSocket.setObjectName("AssignmentClientMonitor");
qCDebug(assigmnentclient) << "Assignment-client monitor socket is" << _assignmentClientMonitorSocket;
// Hook up a timer to send this child's status to the Monitor once per second
setUpStatusToMonitor();
}
auto& packetReceiver = DependencyManager::get<NodeList>()->getPacketReceiver();
packetReceiver.registerListener(PacketType::CreateAssignment, this, "handleCreateAssignmentPacket");
packetReceiver.registerListener(PacketType::StopNode, this, "handleStopNodePacket");
}
示例13: current
MainWidget::MainWidget( QWidget *parent )
: QSplitter( Qt::Horizontal, parent )
, mpKryptonite( new Kryptonite() )
, mpAmazonDE( new KryptoniteJobCoverAmazonDE( mpKryptonite ) )
, mpDiscogs( new KryptoniteJobCoverDiscogs( mpKryptonite ) )
, mpLayout( new QGridLayout( this ) )
, mpFileSysTree( new QTreeView( this ) )
, mpFileSysModel( new QFileSystemModel( this ) )
, mpLineEdit( new QLineEdit( this ) )
, mpFollowPartyman( new QCheckBox( tr("Follow Partyman"), this ) )
, mpCopyBuffer( new QPushButton( tr("Copy debug buffer to clipboard"), this ) )
, mpImage( new DropImageWidget( this ) )
, mpInfo( new QListWidget( this ) )
, mpSignalMapper( new QSignalMapper( this ) )
, mDataMap()
, mCacheMap()
, mDebugData()
{
mpKryptonite->setObjectName( "Downloader");
mpAmazonDE->setObjectName( "Amazon" );
mpDiscogs->setObjectName( "Discogs" );
mpFileSysTree->setObjectName( "FileSysTree" );
mpFileSysModel->setObjectName( "FileSysModel" );
mpLineEdit->setObjectName( "LineInput" );
mpFollowPartyman->setObjectName( "FollowPartyman" );
mpFollowPartyman->setChecked( true );
mpCopyBuffer->setObjectName( "CopyBuffer" );
mpImage->setObjectName( "Image" );
mpInfo->setObjectName( "Info" );
QThread *t = new QThread();
connect( qApp, SIGNAL(aboutToQuit()),
t, SLOT(quit()) );
ProxyWidget::setProxy( mpKryptonite->networkAccessManager() );
mpKryptonite->moveToThread( t );
mpAmazonDE->moveToThread( t );
mpDiscogs->moveToThread( t );
t->setObjectName( "DownloadThread" );
t->start();
QWidget *w = 0;
mpFileSysTree->setModel( mpFileSysModel );
mpFileSysModel->setRootPath( "/" );
mpFileSysModel->setFilter( QDir::NoDotAndDotDot | QDir::AllDirs );
const QString current( Settings::value( Settings::RubberbandmanRootDirectory ) );
QModelIndex qmi( mpFileSysModel->index( current ) );
if( qmi.isValid() )
{
mpFileSysTree->setRootIndex( qmi );
mpFileSysTree->setCurrentIndex( mpFileSysModel->index( current ) );
}
mpFileSysTree->header()->hide();
mpFileSysTree->setColumnHidden( 1, true );
mpFileSysTree->setColumnHidden( 2, true );
mpFileSysTree->setColumnHidden( 3, true );
QSplitter *s = new QSplitter( Qt::Vertical, this );
w = new QWidget( this );
QVBoxLayout *v = new QVBoxLayout( w );
v->addWidget( mpFileSysTree );
v->addWidget( mpLineEdit );
QHBoxLayout *h = new QHBoxLayout();
v->addLayout( h );
h->addWidget( mpFollowPartyman );
h->addWidget( mpCopyBuffer );
s->addWidget( w );
w = new QWidget( this );
w->setLayout( mpLayout );
s->addWidget( w );
addWidget( s );
w = new QWidget( this );
v = new QVBoxLayout( w );
v->addWidget( mpImage );
v->addWidget( mpInfo );
addWidget( w );
v->setStretch( 0, 1 );
Satellite *satellite = Satellite::get();
connect( mpImage, SIGNAL(droppedUrl(QUrl)),
this, SLOT(saveImage(QUrl)) );
connect( mpCopyBuffer, SIGNAL(clicked()),
this, SLOT(debugBufferToClipboard()) );
connect( mpLineEdit, SIGNAL(returnPressed()),
this, SLOT(requestFromLine()) );
connect( mpFileSysTree, SIGNAL(clicked(QModelIndex)),
this, SLOT(entryClicked(QModelIndex)) );
connect( mpSignalMapper, SIGNAL(mapped(QWidget*)),
this, SLOT(saveImage(QWidget*)) );
connect( this, SIGNAL(requestSearch(QString)),
mpDiscogs, SLOT(requestList(QString)) );
connect( mpDiscogs, SIGNAL(imageFound(QByteArray,QVariant)),
this, SLOT(addThumbnail(QByteArray,QVariant)) );
connect( mpDiscogs, SIGNAL(imageDownloaded(QByteArray,QVariant)),
this, SLOT(showImage(QByteArray,QVariant)) );
connect( mpDiscogs, SIGNAL(message(QString,QByteArray)),
this, SLOT(message(QString,QByteArray)) );
connect( this, SIGNAL(requestSearch(QString)),
mpAmazonDE, SLOT(requestList(QString)) );
connect( mpAmazonDE, SIGNAL(imageFound(QByteArray,QVariant)),
this, SLOT(addThumbnail(QByteArray,QVariant)) );
connect( mpAmazonDE, SIGNAL(imageDownloaded(QByteArray,QVariant)),
this, SLOT(showImage(QByteArray,QVariant)) );
//.........这里部分代码省略.........
示例14: ProcessData
//.........这里部分代码省略.........
{
qWarning() << "CNetRender - version mismatch! client version: " << version << ", server: " << *(qint32*)inMsg->payload.data();
outMsg.command = netRender_BAD;
}
SendData(clientSocket, outMsg);
break;
}
case netRender_STOP:
{
status = netRender_READY;
gMainInterface->stopRequest = true;
emit NotifyStatus();
WriteLog("CNetRender - STOP");
break;
}
case netRender_STATUS:
{
emit NotifyStatus();
break;
}
case netRender_JOB:
{
if (inMsg->id == actualId)
{
WriteLog("NetRender - received new job");
QDataStream stream(&inMsg->payload, QIODevice::ReadOnly);
QByteArray buffer;
qint32 size;
status = netRender_WORKING;
emit NotifyStatus();
// read settings
stream >> size;
buffer.resize(size);
stream.readRawData(buffer.data(), size);
settingsText = QString::fromUtf8(buffer.data(), buffer.size());
// read textures
for (int i = 0; i < textures.textureList.size(); i++)
{
stream >> size;
if (size > 0)
{
buffer.resize(size);
stream.readRawData(buffer.data(), size);
textures.textureList[i]->FromQByteArray(buffer);
}
}
cSettings parSettings(cSettings::formatCondensedText);
parSettings.BeQuiet(true);
parSettings.LoadFromString(settingsText);
parSettings.Decode(gPar, gParFractal);
if(!systemData.noGui)
{
gMainInterface->SynchronizeInterface(gPar, gParFractal, cInterface::write);
gMainInterface->StartRender(true);
}
else
{
//in noGui mode it must be started as separate thread to be able to process event loop
gMainInterface->headless = new cHeadless;
QThread *thread = new QThread; //deleted by deleteLater()
gMainInterface->headless->moveToThread(thread);
QObject::connect(thread, SIGNAL(started()), gMainInterface->headless, SLOT(slotNetRender()));
thread->setObjectName("RenderJob");
thread->start();
QObject::connect(gMainInterface->headless, SIGNAL(finished()), gMainInterface->headless, SLOT(deleteLater()));
QObject::connect(gMainInterface->headless, SIGNAL(finished()), thread, SLOT(quit()));
QObject::connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
}
}
else
{
WriteLog("NetRender - received JOB message with wrong id");
}
break;
}
case netRender_RENDER:
{
if (inMsg->id == actualId)
{
QDataStream stream(&inMsg->payload, QIODevice::ReadOnly);
qint32 doneSize;
stream >> doneSize;
QList<int> done;
for (int i = 0; i < doneSize; i++)
{
qint32 line;
stream >> line;
done.append(line);
}
emit ToDoListArrived(done);
}
else
{
示例15: initServer
//.........这里部分代码省略.........
try { if (settingsCache->value("servernetwork/active", 0).toInt()) {
qDebug() << "Connecting to ISL network.";
const QString certFileName = settingsCache->value("servernetwork/ssl_cert").toString();
const QString keyFileName = settingsCache->value("servernetwork/ssl_key").toString();
qDebug() << "Loading certificate...";
QFile certFile(certFileName);
if (!certFile.open(QIODevice::ReadOnly))
throw QString("Error opening certificate file: %1").arg(certFileName);
QSslCertificate cert(&certFile);
const QDateTime currentTime = QDateTime::currentDateTime();
if(currentTime < cert.effectiveDate() ||
currentTime > cert.expiryDate() ||
cert.isBlacklisted())
throw(QString("Invalid certificate."));
qDebug() << "Loading private key...";
QFile keyFile(keyFileName);
if (!keyFile.open(QIODevice::ReadOnly))
throw QString("Error opening private key file: %1").arg(keyFileName);
QSslKey key(&keyFile, QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey);
if (key.isNull())
throw QString("Invalid private key.");
QMutableListIterator<ServerProperties> serverIterator(serverList);
while (serverIterator.hasNext()) {
const ServerProperties &prop = serverIterator.next();
if (prop.cert == cert) {
serverIterator.remove();
continue;
}
QThread *thread = new QThread;
thread->setObjectName("isl_" + QString::number(prop.id));
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
IslInterface *interface = new IslInterface(prop.id, prop.hostname, prop.address.toString(), prop.controlPort, prop.cert, cert, key, this);
interface->moveToThread(thread);
connect(interface, SIGNAL(destroyed()), thread, SLOT(quit()));
thread->start();
QMetaObject::invokeMethod(interface, "initClient", Qt::BlockingQueuedConnection);
}
const int networkPort = settingsCache->value("servernetwork/port", 14747).toInt();
qDebug() << "Starting ISL server on port" << networkPort;
islServer = new Servatrice_IslServer(this, cert, key, this);
if (islServer->listen(QHostAddress::Any, networkPort))
qDebug() << "ISL server listening.";
else
throw QString("islServer->listen()");
} } catch (QString error) {
qDebug() << "ERROR --" << error;
return false;
}
pingClock = new QTimer(this);
connect(pingClock, SIGNAL(timeout()), this, SIGNAL(pingClockTimeout()));
pingClock->start(pingClockInterval * 1000);
int statusUpdateTime = settingsCache->value("server/statusupdate", 15000).toInt();
statusUpdateClock = new QTimer(this);
connect(statusUpdateClock, SIGNAL(timeout()), this, SLOT(statusUpdate()));
if (statusUpdateTime != 0) {
qDebug() << "Starting status update clock, interval " << statusUpdateTime << " ms";