当前位置: 首页>>代码示例>>C++>>正文


C++ QEventLoop::connect方法代码示例

本文整理汇总了C++中QEventLoop::connect方法的典型用法代码示例。如果您正苦于以下问题:C++ QEventLoop::connect方法的具体用法?C++ QEventLoop::connect怎么用?C++ QEventLoop::connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QEventLoop的用法示例。


在下文中一共展示了QEventLoop::connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: inPort

void KPAOS4Checker::check()
{
    QString inPort(Settings::get().getMidiInPort());
    QString outPort(Settings::get().getMidiOutPort());

    if(inPort.isEmpty() || outPort.isEmpty())
    {
        SettingsDialog settingsDialog(nullptr);
        settingsDialog.exec();
        inPort = Settings::get().getMidiInPort();
        outPort = Settings::get().getMidiOutPort();
    }

    if(Midi::get().openPorts(inPort, outPort))
    {
        QEventLoop el;
        el.connect(this, &KPAOS4Checker::stopLoop, &el, &QEventLoop::quit);
        el.connect(&stompDelayObj, &Stomp::onOffReceived, this, &KPAOS4Checker::onOfReceived);
        el.connect(mTimer, &QTimer::timeout, this, &KPAOS4Checker::timerTimeout);
        mTimer->start(500);
        stompDelayObj.requestOnOff();
        el.exec();
        el.disconnect(this, &KPAOS4Checker::stopLoop, &el, &QEventLoop::quit);
        el.disconnect(&stompDelayObj, &Stomp::onOffReceived, this, &KPAOS4Checker::onOfReceived);
        el.disconnect(mTimer, &QTimer::timeout, this, &KPAOS4Checker::timerTimeout);
    }
}
开发者ID:virango,项目名称:Toaster,代码行数:27,代码来源:KPAOS4Checker.cpp

示例2: main

int main(int argc, char** argv) try
{
    if (argc < 2) {
        std::cerr << "usage: " << argv[0] << " path" << std::endl;
        return 1;
    }
 
    QCoreApplication app(argc, argv);
    QEventLoop loop;
    
    QString const path = QFile::decodeName(argv[1]);
    
    lastfm::Track t = lastfm::taglib(path); //see contrib //TODO mbid
    lastfm::Fingerprint fp(t);
    if (fp.id().isNull()) {
        lastfm::FingerprintableSource* src = factory(typeOf(path));
        fp.generate(src);
        QNetworkReply* reply = fp.submit();
        loop.connect(reply, SIGNAL(finished()), SLOT(quit()));
        fp.decode(reply);
    }
    
    QNetworkReply* reply = fp.id().getSuggestions();
    loop.connect(reply, SIGNAL(finished()), SLOT(quit()));
    
    std::cout << reply->readAll().data() << std::endl; //returns XML
    return 0;
}
catch (std::exception& e)
{
    std::cerr << e.what() << std::endl;
}
开发者ID:LittleForker,项目名称:tomahawk,代码行数:32,代码来源:main.cpp

示例3: testList

void CatalogTest::testList()
{
    QNetworkReply* reply = Echonest::Catalog::list();

    qDebug() << reply->url().toString();
    QCOMPARE( reply->url().toString(), QLatin1String( "http://developer.echonest.com/api/v4/catalog/list?api_key=JGJCRKWLXLBZIFAZB&format=xml" ) );

    QEventLoop loop;
    loop.connect( reply, SIGNAL(finished()), SLOT(quit()) );
    loop.exec();

    Echonest::Catalogs catalogs = Echonest::Catalog::parseList( reply );
    qDebug() << catalogs.size();
    qDebug() << catalogs;
    QVERIFY( !catalogs.isEmpty() );

    // Now limit it to just 1, but the second one.
    reply = Echonest::Catalog::list( 1, 1 );

    qDebug() << reply->url().toString();
    QCOMPARE( reply->url().toString(), QLatin1String( "http://developer.echonest.com/api/v4/catalog/list?api_key=JGJCRKWLXLBZIFAZB&format=xml&results=1&start=1" ) );

    loop.connect( reply, SIGNAL(finished()), SLOT(quit()) );
    loop.exec();

    catalogs = Echonest::Catalog::parseList( reply );
    qDebug() << catalogs.size();
    QCOMPARE( catalogs.size(), 1 );
}
开发者ID:xhochy,项目名称:libechonest,代码行数:29,代码来源:CatalogTest.cpp

示例4: SIGNAL

http::Response * Server::wait(QFuture<http::Response *> future) {
	
	QEventLoop loop;
	
	// Interrrupt the event loop when the result is available
	QFutureWatcher<http::Response *> watcher;
	watcher.setFuture(future);
	loop.connect(&watcher, SIGNAL(finished()), SLOT(quit()));
	
	// Prevent infinite loop if the future completes before we start the loop
	QTimer timer;
	loop.connect(&timer, SIGNAL(timeout()), SLOT(quit()));
	timer.setSingleShot(false);
	timer.start(1000);
	
	// Process events while waiting so that the UI stays responsive
	while(!future.isFinished()) {
		loop.exec();
	}
	
	http::Response * response = future.result();
	
	if(response->ok()) {
		m_lastErrorString.clear();
	} else if(!response->error().empty()) {
		m_lastErrorString = toQString(response->error());
	} else if(!response->data().empty()) {
		m_lastErrorString = toQString(response->data());
	} else {
		m_lastErrorString = "HTTP Error " + QString::number(response->status());
	}
	
	return response;
}
开发者ID:bsxf-47,项目名称:ArxLibertatis,代码行数:34,代码来源:TBG.cpp

示例5: testCreateUpdateDeleteArtist

void CatalogTest::testCreateUpdateDeleteArtist()
{
    try {
        QNetworkReply* reply = Echonest::Catalog::create( QLatin1String( "unittest_catalog_artist_X" ), Echonest::CatalogTypes::Artist );
    //
        QEventLoop loop;
        loop.connect( reply, SIGNAL(finished()), SLOT(quit()) );
        loop.exec();

        m_artistC = Echonest::Catalog::parseCreate( reply );
        qDebug() << "CREATED NEW ARTIST CATALOG:" << m_artistC;
        QVERIFY( !m_artistC.id().isEmpty() );
        QVERIFY( !m_artistC.name().isEmpty() );

    //         c = Echonest::Catalog( "CAPRWVK12BFA1A6F17" );

        Echonest::CatalogUpdateEntry entry;
        entry.setArtistName( QLatin1String( "Balmorhea" ) );
        entry.setGenre( QLatin1String( "Post Rock" ) );
        entry.setAction( Echonest::CatalogTypes::Update );
        Echonest::CatalogUpdateEntry entry2;
        entry2.setArtistName( QLatin1String( "Mono" ) );
        entry2.setGenre( QLatin1String( "Post Rock" ) );
        entry2.setAction( Echonest::CatalogTypes::Update );
        Echonest::CatalogUpdateEntries entries;
        entries << entry << entry2;

        reply = m_artistC.update( entries );
        loop.connect( reply, SIGNAL(finished()), SLOT(quit()) );
        loop.exec();

        QByteArray ticket = Echonest::Catalog::parseTicket( reply );
        qDebug() << ticket;

        QVERIFY( !ticket.isEmpty() );
        // now check the ticket status after 5s
        QTest::qWait( 10000 );
        reply = Echonest::Catalog::status( ticket );
        loop.connect( reply, SIGNAL(finished()), SLOT(quit()) );
        loop.exec();
        Echonest::CatalogStatus cs = Echonest::Catalog::parseStatus( reply );
        qDebug() << "Catalog status:" << cs.status << cs.items_updated << cs.items;

        // now read the catalog
        reply = m_artistC.readSongCatalog();
        loop.connect( reply, SIGNAL(finished()), SLOT(quit()) );
        loop.exec();
        m_artistC.parseRead( reply );
        qDebug() << m_artistC;
        QCOMPARE( m_artistC.artists().size(), 2 );
    } catch( const Echonest::ParseError& e ) {
        qWarning() << "Got exception, failing:" << e.what();
        QVERIFY( false );
    }
}
开发者ID:xhochy,项目名称:libechonest,代码行数:55,代码来源:CatalogTest.cpp

示例6: waitForSignal

// http://stackoverflow.com/questions/2629055/qtestlib-qnetworkrequest-not-executed
bool waitForSignal(QObject *sender, const char *signal, int timeout = 1000) {
	QEventLoop loop;
	QTimer timer;
	timer.setInterval(timeout);
	timer.setSingleShot(true);

	loop.connect(sender, signal, SLOT(quit()));
	loop.connect(&timer, SIGNAL(timeout()), SLOT(quit()));
	timer.start();
	loop.exec();

	return timer.isActive();
}
开发者ID:barcodetickets,项目名称:bts-client,代码行数:14,代码来源:api.cpp

示例7: cleanupTestCase

void CatalogTest::cleanupTestCase()
{
    // delete the two test catalogs we created
    qDebug() << "Deleting catalogs!";
    QNetworkReply* reply = m_songC.deleteCatalog();
    QEventLoop loop;
    loop.connect( reply, SIGNAL(finished()), SLOT(quit()) );
    loop.exec();

    reply = m_artistC.deleteCatalog();
    loop.connect( reply, SIGNAL(finished()), SLOT(quit()) );
    loop.exec();
    return;
}
开发者ID:xhochy,项目名称:libechonest,代码行数:14,代码来源:CatalogTest.cpp

示例8: addUser

/*!
 * @brief       Add a user
 * @param[in]   username
 * @param[in]   password
 * @param[in]   access_level
 * @return      Returns a string, if successful "OK" otherwise an error
 */
QString AdminRPC::addUser(const QString &username, const QString &password, int access_level)
{
    QString result;
    uint64_t fake_session_token = s_last_token++;
    int token = static_cast<int>(fake_session_token);

    // Create and insert a record of this request into m_completion_state
    m_completion_state.insert(token, "");

    qCDebug(logRPC) << "addUser call in progress";

    EventProcessor *tgt = HandlerLocator::getAuthDB_Handler();
    tgt->putq(new CreateAccountMessage({username, password, access_level}, fake_session_token, this));

    QTimer response_timer;
    QTimer timeout;
    timeout.setSingleShot(true);
    QEventLoop loop;
    loop.connect(&timeout, SIGNAL(timeout()), SLOT(quit()));
    loop.connect(this, SIGNAL(responseRecieved()), SLOT(quit()));
    loop.connect(&response_timer, &QTimer::timeout, [=] () {
        if (!m_completion_state[token].isEmpty())
        {
            emit responseRecieved(); // Response recieved we can break out of event loop
            return;
        }
        else
            return;
    });
    response_timer.start(500); // Checks completion status every 500ms
    timeout.start(5000); // Timeout of 5 seconds in case something goes wrong.
    loop.exec();

    if (!m_completion_state[token].isEmpty())
    {
        result = m_completion_state[token];
        response_timer.stop();
        m_completion_state.remove(token); // Tidy up
    }
    else
    {
        result = "Something went wrong";
        response_timer.stop();
        m_completion_state.remove(token);
    }

    return result;
}
开发者ID:Segs,项目名称:Segs,代码行数:55,代码来源:AdminRPC.cpp

示例9: qDebug

void PlaylistTest::testStatic2()
{
    DynamicPlaylist::PlaylistParams p;
    p.append( DynamicPlaylist::PlaylistParamData( DynamicPlaylist::Artist, QLatin1String( "tallest man on earth" ) ) );
    p.append( DynamicPlaylist::PlaylistParamData( DynamicPlaylist::Artist, QLatin1String( "bon iver" ) ) );
    p.append( DynamicPlaylist::PlaylistParamData( DynamicPlaylist::Artist, QLatin1String( "mumford and sons" ) ) );
    p.append( DynamicPlaylist::PlaylistParamData( DynamicPlaylist::Artist, QLatin1String( "Florence + The Machine" ) ) );
    p.append( DynamicPlaylist::PlaylistParamData( DynamicPlaylist::ArtistMaxFamiliarity, 0.4 ) );
    p.append( DynamicPlaylist::PlaylistParamData( DynamicPlaylist::MinDanceability, 0.7 ) );
    p.append( DynamicPlaylist::PlaylistParamData( DynamicPlaylist::Type, Echonest::DynamicPlaylist::ArtistType ) );
    p.append( DynamicPlaylist::PlaylistParamData( DynamicPlaylist::SongInformation, QVariant::fromValue( Echonest::SongInformation( Echonest::SongInformation::Hotttnesss | Echonest::SongInformation::ArtistHotttnesss | Echonest::SongInformation::ArtistFamiliarity ) ) ) );
    p.append( DynamicPlaylist::PlaylistParamData( DynamicPlaylist::Results, 4 ) );

    QNetworkReply* reply = DynamicPlaylist::staticPlaylist( p );

    qDebug() << reply->url().toEncoded();
    QCOMPARE( QLatin1String( reply->url().toEncoded() ), QLatin1String( "http://developer.echonest.com/api/v4/playlist/static?api_key=JGJCRKWLXLBZIFAZB&format=xml&artist=tallest+man+on+earth&artist=bon+iver&artist=mumford+and+sons&artist=Florence+%2B+The+Machine&artist_max_familiarity=0.4&min_danceability=0.7&type=artist&bucket=song_hotttnesss&bucket=artist_hotttnesss&bucket=artist_familiarity&results=4" ) );

    QEventLoop loop;
    loop.connect( reply, SIGNAL(finished()), SLOT(quit()) );
    loop.exec();
    SongList songs = DynamicPlaylist::parseStaticPlaylist( reply );

//     qDebug() << "Got songs;" << songs;
    QVERIFY( songs.size() > 1 );
    Q_FOREACH( const Song& song, songs ) {
        QVERIFY( !song.id().isEmpty() );
    }
开发者ID:xhochy,项目名称:libechonest,代码行数:28,代码来源:PlaylistTest.cpp

示例10: download

bool ExportCommon::download(ExportContext *ctx, QString url, QString to) {
	QString filePath = QDir::cleanPath(ctx->outputDir.absoluteFilePath(to));
	QFileInfo fi = QFileInfo(filePath);
	ctx->outputDir.mkpath(fi.dir().absolutePath());
	QFile file(filePath);
	if (file.exists())
		return true;
	if (file.open(QIODevice::WriteOnly)) {
		exportInfo("Downloading %s\n", url.toStdString().c_str());

		QUrl imageUrl(url);
		FileDownloader *m_pImgCtrl = new FileDownloader(imageUrl);

		QEventLoop loop;
		loop.connect(m_pImgCtrl, SIGNAL(downloaded()), &loop, SLOT(quit()));
		loop.exec();

		QByteArray data = m_pImgCtrl->downloadedData();

		delete m_pImgCtrl;

		if (data.length() > 0) {
			file.write(data);
			return true;
		} else
			exportError("Failed to download %s\n", url.toStdString().c_str());
	} else
		exportError("Can't open file %s\n", to.toStdString().c_str());
	return false;
}
开发者ID:jdbcdev,项目名称:gideros,代码行数:30,代码来源:ExportCommon.cpp

示例11: sendData

void MainWindow::sendData(const QString &data)
{
    // Quick error checks before sending
    if (data.isEmpty())
    {
        showError(tr("Can't process audio ;("));
        return;
    }

    ui->label->setText(tr("Sending data..."));
    ui->recordButton->setIcon(*iconNetwork);
    repaint();

#ifdef USE_LIBECHONEST
    QNetworkReply * reply = Echonest::Song::identify(data);
    QEventLoop loop;
    loop.connect(reply, SIGNAL(finished()), SLOT(quit()));
    loop.exec();

    QByteArray answer(reply->readAll());
#else
    EchoNestRequest request(this, nam, API_KEY, QString("4.11"));
    EchoNestSong * song = request.identifySong(data);
#endif

    emit(resultReady(song));
}
开发者ID:artturi2511,项目名称:qechoprint,代码行数:27,代码来源:mainwindow.cpp

示例12: LoadRemote

void SongLoader::LoadRemote() {
  qLog(Debug) << "Loading remote file" << url_;

  // It's not a local file so we have to fetch it to see what it is.  We use
  // gstreamer to do this since it handles funky URLs for us (http://, ssh://,
  // etc) and also has typefinder plugins.
  // First we wait for typefinder to tell us what it is.  If it's not text/plain
  // or text/uri-list assume it's a song and return success.
  // Otherwise wait to get 512 bytes of data and do magic on it - if the magic
  // fails then we don't know what it is so return failure.
  // If the magic succeeds then we know for sure it's a playlist - so read the
  // rest of the file, parse the playlist and return success.

  timeout_timer_->start(timeout_);

  // Create the pipeline - it gets unreffed if it goes out of scope
  std::shared_ptr<GstElement> pipeline(gst_pipeline_new(nullptr),
                                       std::bind(&gst_object_unref, _1));

  // Create the source element automatically based on the URL
  GstElement* source = gst_element_make_from_uri(
      GST_URI_SRC, url_.toEncoded().constData(), nullptr, nullptr);
  if (!source) {
    qLog(Warning) << "Couldn't create gstreamer source element for"
                  << url_.toString();
    return;
  }

  // Create the other elements and link them up
  GstElement* typefind = gst_element_factory_make("typefind", nullptr);
  GstElement* fakesink = gst_element_factory_make("fakesink", nullptr);

  gst_bin_add_many(GST_BIN(pipeline.get()), source, typefind, fakesink,
                   nullptr);
  gst_element_link_many(source, typefind, fakesink, nullptr);

  // Connect callbacks
  GstBus* bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline.get()));
  CHECKED_GCONNECT(typefind, "have-type", &TypeFound, this);
  gst_bus_set_sync_handler(bus, BusCallbackSync, this, NULL);
  gst_bus_add_watch(bus, BusCallback, this);

  // Add a probe to the sink so we can capture the data if it's a playlist
  GstPad* pad = gst_element_get_static_pad(fakesink, "sink");
  gst_pad_add_probe(pad, GST_PAD_PROBE_TYPE_BUFFER, &DataReady, this, NULL);
  gst_object_unref(pad);

  QEventLoop loop;
  loop.connect(this, SIGNAL(LoadRemoteFinished()), SLOT(quit()));

  // Start "playing"
  gst_element_set_state(pipeline.get(), GST_STATE_PLAYING);
  pipeline_ = pipeline;

  // Wait until loading is finished
  loop.exec();
}
开发者ID:Chemrat,项目名称:Clementine,代码行数:57,代码来源:songloader.cpp

示例13: run

void EventQueue::run() {
	QEventLoop loop;
	loop.connect(this, SIGNAL(_stop()), SLOT(quit()));
	Task bgTask;
	this->_bgTask = &bgTask;
	this->_bgTask->setMouseArea(this->_view);
	emit this->_started();
	loop.exec();
	this->_bgTask = nullptr;
	emit this->_stopped();
}
开发者ID:Manuel4131,项目名称:junkcode,代码行数:11,代码来源:eventqueue.cpp

示例14: put

void LedDevicePhilipsHue::put(QString route, QString content) {
	QString url = QString("http://%1/api/%2/%3").arg(host).arg(username).arg(route);
	// Perfrom request
	QNetworkRequest request(url);
	QNetworkReply* reply = manager->put(request, content.toLatin1());
	// Connect finished signal to quit slot of the loop.
	QEventLoop loop;
	loop.connect(reply, SIGNAL(finished()), SLOT(quit()));
	// Go into the loop until the request is finished.
	loop.exec();
}
开发者ID:Manbient,项目名称:hyperion,代码行数:11,代码来源:LedDevicePhilipsHue.cpp

示例15: SIGNAL

char *gui_debug_prompt()
{
    #ifdef MOBILE_UI
        return const_cast<char*>("c");
    #else
        QEventLoop ev;
        ev.connect(main_window, SIGNAL(debuggerCommand()), &ev, SLOT(quit()));
        ev.exec();
        return main_window->debug_command.data();
    #endif
}
开发者ID:p0wer0n,项目名称:firebird,代码行数:11,代码来源:emuthread.cpp


注:本文中的QEventLoop::connect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。