コード例 #1
0
ファイル: cutenews.cpp プロジェクト: marxoft/cutenews
bool CuteNews::quit() {
    if (m_connection) {
        m_connection->close();
    }
    
    QThread *dbThread = DBConnection::asynchronousThread();

    if ((dbThread) && (dbThread != QThread::currentThread())) {
        if (dbThread->isRunning()) {
            Logger::log("CuteNews::quit(). Shutting down the database thread", Logger::LowVerbosity);
            connect(dbThread, SIGNAL(finished()), this, SLOT(quit()), Qt::UniqueConnection);
            dbThread->quit();
            return false;
        }
    }
        
    const int expiryDays = Settings::readArticleExpiry();
    
    if (expiryDays > -1) {
        uint expiryDate = QDateTime::currentDateTime().toTime_t();

        if (expiryDays > 0) {
            expiryDate -= expiryDays * 86400;
        }
        
        Logger::log("CuteNews::quit(). Deleting read articles older than "
                    + QDateTime::fromTime_t(expiryDate).toString(Qt::ISODate));
        DBConnection(false).deleteExpiredArticles(expiryDate);
    }
    
    Transfers::instance()->save();
    Logger::log("CuteNews::quit(). Quitting the application", Logger::LowVerbosity);
    QCoreApplication::quit();
    return true;
}
コード例 #2
0
ファイル: main.cpp プロジェクト: vrichter/gazetool
int main(int argc, char** argv) {
    auto worker = std::make_shared<WorkerThread>();
    auto options = parse_options(argc,argv);
    set_options(*worker,options);

    auto publishers = create_publishers(*worker,options);

    // gui mode
    if (!options.count("novis")){
#ifdef ENABLE_QT5
        qRegisterMetaType<GazeHypsPtr>();
        qRegisterMetaType<std::string>();
        QApplication app(argc, argv);
        GazerGui gui;
        set_options(gui,options);
        WorkerAdapter gazer(worker);
        QThread thread;
        gazer.moveToThread(&thread);

        QObject::connect(&app, SIGNAL(lastWindowClosed()), &gazer, SLOT(stop()));
        QObject::connect(&gazer, SIGNAL(finished()), &thread, SLOT(quit()));
        QObject::connect(&gazer, SIGNAL(imageProcessed(GazeHypsPtr)), &gui,
                         SLOT(displayGazehyps(GazeHypsPtr)), Qt::QueuedConnection);
        QObject::connect(&gazer, SIGNAL(statusmsg(std::string)), &gui, SLOT(setStatusmsg(std::string)));
        QObject::connect(&thread, SIGNAL(started()), &gazer, SLOT(process()));
        QObject::connect(&gui, SIGNAL(horizGazeToleranceChanged(double)), &gazer, SLOT(setHorizGazeTolerance(double)));
        QObject::connect(&gui, SIGNAL(verticalGazeToleranceChanged(double)), &gazer, SLOT(setVerticalGazeTolerance(double)));
        QObject::connect(&gui, SIGNAL(smoothingChanged(bool)), &gazer, SLOT(setSmoothing(bool)));
        if (!options.count("noquit")) {
            QObject::connect(&gazer, SIGNAL(finished()), &app, SLOT(quit()));
        }

        gui.show();
        thread.start();
        auto result = app.exec();
        //process events after event loop terminates allowing unfinished threads to send signals
        while (thread.isRunning()) {
            thread.wait(10);
            QCoreApplication::processEvents();
        }
        return result;
#else
        cerr << "Appplication build without qt. Assuming --novis" << std::endl;
#endif
    }
コード例 #3
0
ファイル: sshsocket.cpp プロジェクト: kesrut/ServerMonitorN9
void sshsocket::edit()
{
    QTimer *timer = servers->at(index)->getTimer() ;
    if (timer != NULL)
    {
        if (timer->isActive())
        {
            timer->stop() ;
            delete timer ;
        }
    }

    QThread *thread = (QThread*)host->getThread() ;
    if (thread != NULL)
    {
        if (thread->isRunning())
        {
            thread->exit();
        }
    }
    servers->replace(index, host);
    model->new_updt(index);
}
コード例 #4
0
ファイル: skp_socket_test_widget.cpp プロジェクト: yefy/skp
SkpSocketTestWidget::SkpSocketTestWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::SkpSocketTestWidget),
    m_writeSize(0),
    m_readSize(0),
    m_sec(0),
    m_readavgSize(0),
    m_writavgeSize(0),

    m_connectNumber(0),
    m_realConnect(0),
    m_closeNumber(0),
    m_errorConnect(0),
    m_max(0),
    m_isStart(false),
    m_autoConnectNumber(0),
    m_showPrintNumber(0)
{
    ui->setupUi(this);

    //qDebug() << "main ID" << (qint64)QThread::currentThreadId();
    m_autoConnectNumber = 100;
    m_showPrintNumber = 1000;
    g_ShowPrintNumber = m_showPrintNumber;
    ui->autoconnect_lineEdit->setText(QString::number(m_autoConnectNumber));
    ui->showPrint_lineEdit->setText(QString::number(m_showPrintNumber));

    connect(&m_timer, SIGNAL(timeout()), this, SLOT(skp_on_timer_socket()));

    connect(ui->startTimer, SIGNAL(clicked()), this, SLOT(skp_on_timeout_start()));
    connect(ui->stopTimer, SIGNAL(clicked()), this, SLOT(skp_on_timeout_stop()));
    connect(ui->timerOnce, SIGNAL(clicked()), this, SLOT(skp_on_timer_socket_once()));

    connect(ui->connectSocket, SIGNAL(clicked()), this, SLOT(skp_on_simple_socket()));
    connect(ui->socketSend, SIGNAL(clicked()), this, SLOT(skp_on_simple_send()));
    connect(ui->socketRecv, SIGNAL(clicked()), this, SLOT(skp_on_simple_recv()));
    connect(ui->socketClose, SIGNAL(clicked()), this, SLOT(skp_on_simple_close()));

    connect(ui->protocolConn, SIGNAL(clicked()), this, SLOT(skp_on_simple_protocol()));
    connect(ui->protocolConnClose, SIGNAL(clicked()), this, SLOT(skp_on_simple_protocol_close()));

    connect(&m_statisticsTimer, SIGNAL(timeout()), this, SLOT(skp_on_print()));
    ///yefy___
    //m_statisticsTimer.start(5000);

    connect(&m_taskTimer, SIGNAL(timeout()), this, SLOT(skp_on_socket_task_start()));
    connect(ui->timerTaskStart, SIGNAL(clicked()), this, SLOT(skp_on_timer_task_start()));
    connect(ui->onceSocketTaskStart, SIGNAL(clicked()), this, SLOT(skp_on_socket_task_start()));
    connect(ui->ok_pushButton, SIGNAL(clicked()), this, SLOT(skp_on_socket_conf()));

    for(int i = 0; i < THREAD_NUMBER; i++) {
        QThread *thread = new QThread();
        m_threadList.push_back(thread);
        thread->start();
        while(!thread->isRunning()) {
            ;
        }

        SkpTcpSocketTask *tcpSocketTask = new SkpTcpSocketTask();
        tcpSocketTask->moveToThread(thread);
        connect(this, SIGNAL(skp_sig_create_socket()), tcpSocketTask, SLOT(skpOnCreateSocket()));
        connect(tcpSocketTask, SIGNAL(skp_sig_connect()), this, SLOT(skp_on_connect()));
        connect(tcpSocketTask, SIGNAL(skp_sig_quit(qint64, qint64, qint64, qint64)), this, SLOT(skp_on_quit(qint64, qint64, qint64, qint64)));
        connect(tcpSocketTask, SIGNAL(skp_sig_socket_quit(qint64, qint64, qint64, qint64)), this, SLOT(skp_on_socket_quit(qint64, qint64, qint64, qint64)));

    }
}
コード例 #5
0
ファイル: archiveCA_plugin.cpp プロジェクト: caqtdm/caqtdm
// this routine will be called now every 10 seconds to update the cartesianplot
// however when many data it may take much longer, then  suppress any new request
void ArchiveCA_Plugin::Callback_UpdateInterface( QMap<QString, indexes> listOfIndexes)
{
    int nbVal;

    precision = 5;

    // Index name
    stdString index_name =  "/gfa/archiver-data/archive_PRO_ST/index";

    //qDebug() << "====================== ArchiveCA_Plugin::Callback_UpdateInterface";

    QMap<QString, indexes>::const_iterator i = listOfIndexes.constBegin();

    while (i != listOfIndexes.constEnd()) {
        QThread *tmpThread = (QThread *) 0;
        indexes indexNew = i.value();
        //qDebug() << i.key() << ": " << indexNew.indexX << indexNew.indexY << indexNew.pv << indexNew.w << endl;

        nbVal = 0;

        QMap<QString, QThread *>::iterator j = listOfThreads.find(indexNew.key);
        while (j !=listOfThreads.end() && j.key() == indexNew.key) {
            tmpThread = (QThread *) j.value();
            ++j;
        }

        //qDebug() << "tmpThread" << tmpThread;

        if((tmpThread != (QThread *) 0) && tmpThread->isRunning()) {
            //qDebug() << "workerthread is running" << tmpThread->isRunning();
        } else {

            // Get Index name if specified for this widget
            if(caCartesianPlot* w = qobject_cast<caCartesianPlot *>((QWidget*) indexNew.w)) {
                QVariant var = w->property("archiverIndex");
                if(!var.isNull()) {
                    QString indexName = var.toString();
                    index_name = qasc(indexName);
                } else if(indexNew.init){
                    QString mess("ArchiveCA plugin -- no archiverIndex defined as dynamic property in widget "  + w->objectName() + ", defaulting to /gfa/archiver-data/archive_PRO_ST/index");
                    if(messagewindowP != (MessageWindow *) 0) messagewindowP->postMsgEvent(QtWarningMsg, (char*) qasc(mess));
                }
            }

            WorkerCA *worker = new WorkerCA;
            QThread *tmpThread = new QThread;
            listOfThreads.insert(i.key(), tmpThread);
            worker->moveToThread(tmpThread);
            connect(tmpThread, SIGNAL(finished()), worker, SLOT(workerFinish()));
            connect(tmpThread, SIGNAL(finished()), tmpThread, SLOT(deleteLater()) );
            connect(this, SIGNAL(operate( QWidget *, indexes, const stdString)), worker,
                    SLOT(getFromArchive(QWidget *, indexes, stdString)));
            connect(worker, SIGNAL(resultReady(indexes, int, QVector<double>, QVector<double>, QString)), this,
                    SLOT(handleResults(indexes, int, QVector<double>, QVector<double>, QString)));
            tmpThread->start();

            //qDebug() << "CA emit operate";
            emit operate((QWidget *) messagewindowP ,indexNew, index_name);
        }
        ++i;
    }
}