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


C++ QWeakPointer类代码示例

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


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

示例1: QWidget

FlightTaskRowEditor::FlightTaskRowEditor(QWeakPointer<PlanningProblem> problem,
                                         QWeakPointer<FlightTaskArea> area,
                                         QWeakPointer<FlightTask> task,
                                         QWidget *parent) :
    QWidget(parent),
    ui(new Ui::FlightTaskRowEditor),
    _problem(problem),
    _area(area),
    _task(task)
{
    ui->setupUi(this);

    QSharedPointer<FlightTask> strongTask = task.toStrongRef();
    if (strongTask.isNull())
        return;
    QSharedPointer<FlightTaskArea> strongArea = area.toStrongRef();
    if (strongArea.isNull())
        return;

    //Set our label to be the task's name/type
    ui->taskNameLabel->setText(strongTask->taskType());

    //If the task or the area go away we need to close
    connect(strongArea.data(),
            SIGNAL(destroyed()),
            this,
            SLOT(deleteLater()));
    connect(strongTask.data(),
            SIGNAL(destroyed()),
            this,
            SLOT(deleteLater()));
}
开发者ID:Qt-Widgets,项目名称:FlightPlanner,代码行数:32,代码来源:FlightTaskRowEditor.cpp

示例2: sharedTemplateModel

static QSharedPointer<ObjectTemplateModel> sharedTemplateModel()
{
    static QWeakPointer<ObjectTemplateModel> templateModel;
    auto model = templateModel.lock();
    if (model)
        return model;

    model = QSharedPointer<ObjectTemplateModel>::create();
    templateModel = model;

    Preferences *prefs = Preferences::instance();

    // Set the initial root path
    QDir templatesDir(prefs->templatesDirectory());
    if (!templatesDir.exists())
        templatesDir.setPath(QDir::currentPath());
    model->setRootPath(templatesDir.absolutePath());

    // Make sure the root path stays updated
    ObjectTemplateModel *modelPointer = model.data();
    QObject::connect(prefs, &Preferences::templatesDirectoryChanged,
                     modelPointer, [modelPointer] (const QString &templatesDirectory) {
        modelPointer->setRootPath(QDir(templatesDirectory).absolutePath());
    });

    return model;
}
开发者ID:bjorn,项目名称:tiled,代码行数:27,代码来源:templatesdock.cpp

示例3: QObject

void CacheTest::testMaximumCacheSize()
{
    QpCache cache;
    int cacheSize = 10;
    cache.setMaximumCacheSize(cacheSize);

    QWeakPointer<QObject> weakRef = cache.insert(0, new QObject()).toWeakRef();

    QWeakPointer<QObject> weakRef4;
    QWeakPointer<QObject> weakRef5;

    for (int i = 1; i < cacheSize; ++i) {
        QWeakPointer<QObject> weak = cache.insert(i, new QObject()).toWeakRef();
        QVERIFY(weakRef.toStrongRef());

        if (i == 4) {
            weakRef4 = weak;
        }
        if (i == 5) {
            weakRef5 = weak;
        }
    }

    cache.insert(10, new QObject());
    QVERIFY(!weakRef.toStrongRef());

    cache.setMaximumCacheSize(6);

    QVERIFY(!weakRef4.toStrongRef());
    QVERIFY(weakRef5.toStrongRef());
}
开发者ID:lbproductions,项目名称:MorQ,代码行数:31,代码来源:tst_cachetest.cpp

示例4: dialogPtr

void LocationEditor::buttonClicked() {
    const QWeakPointer<LocationDialog> dialogPtr(new LocationDialog(this));
    if (LocationDialog *const dialog = dialogPtr.data()) {
        dialog->setLongitude(this->startLongitude);
        dialog->setLatitude(this->startLatitude);
        dialog->setAltitude(this->startAltitude);
        dialog->exec();
    }

    if (LocationDialog *const dialog = dialogPtr.data()) {
        const double lon = dialog->getLongitude();
        const double lat = dialog->getLatitude();
        const double alt = dialog->getAltitude();
        startAltitude = alt;
        startLongitude = lon;
        startLatitude = lat;
        if (dialog->okPressed()) {
            NoteTable ntable(global.db);
            if (lon == 0.0 && lat == 0.0) {
                setText(defaultText);
                ntable.resetGeography(currentLid, true);
            } else {
                setText(dialog->locationText());
                ntable.setGeography(currentLid, lon,lat,alt, true);
            }
        }
        delete dialog;
    }
}
开发者ID:AustinPowered,项目名称:Nixnote2,代码行数:29,代码来源:locationeditor.cpp

示例5: onHeadersComplete

int onHeadersComplete(http_parser *parser)
{   
    TcpSocket *socket = static_cast<TcpSocket*>(parser->data);
#ifndef NO_LOG
    sLog(LogEndpoint::LogLevel::DEBUG) << " === parsed header ====";
    const QHash<QString, QSharedPointer<QString>> &headers = socket->getHeader().getHeaderInfo();

    QHash<QString, QSharedPointer<QString>>::const_iterator i = headers.constBegin();
    while (i != headers.constEnd())
    {
        sLog(LogEndpoint::LogLevel::DEBUG) << i.key() << *(i.value().data());
        ++i;
    }
    sLog(LogEndpoint::LogLevel::DEBUG) << " === ============= ====";
    sLogFlush();
#endif
    QWeakPointer<QString> host = socket->getHeader().getHeaderInfo("Host");

    if (!host.isNull())
    {
        socket->getHeader().setHost(*host.data());
    }

    return 0;
}
开发者ID:shi-yan,项目名称:Swiftly,代码行数:25,代码来源:Worker.cpp

示例6: handleAreaObjectDestroyed

void ProblemModelAdapter::handleAreaObjectDestroyed()
{
    QSharedPointer<PlanningProblem> strongProblem = _problem.toStrongRef();
    if (strongProblem.isNull())
        return;

    QObject * sender = QObject::sender();
    if (!sender)
        return;

    /*
     Don't do anything with this pointer! At this point TaskAreaObject's destructor has
     finished and QObject's destructor is running.
    */
    TaskAreaObject * obj = (TaskAreaObject *)sender;

    if (!_objectToArea.contains(obj))
        return;

    QWeakPointer<TaskArea> weakArea = _objectToArea.take(obj);
    QSharedPointer<TaskArea> area = weakArea.toStrongRef();

    if (!area.isNull())
        strongProblem->removeArea(area);
}
开发者ID:FlavioFalcao,项目名称:Genetic-Planner,代码行数:25,代码来源:ProblemModelAdapter.cpp

示例7: switch

// The access function for guarded QObject pointers.
static void *qpointer_access_func(sipSimpleWrapper *w, AccessFuncOp op)
{
#if QT_VERSION >= 0x040500
    QWeakPointer<QObject> *guard = reinterpret_cast<QWeakPointer<QObject> *>(w->data);
#else
    QObjectGuard *guard = reinterpret_cast<QObjectGuard *>(w->data);
#endif
    void *addr;

    switch (op)
    {
    case UnguardedPointer:
#if QT_VERSION >= 0x040500
        addr = guard->data();
#else
        addr = guard->unguarded;
#endif
        break;

    case GuardedPointer:
#if QT_VERSION >= 0x040500
        addr = guard->isNull() ? 0 : guard->data();
#else
        addr = (QObject *)guard->guarded;
#endif
        break;

    case ReleaseGuard:
        delete guard;
        addr = 0;
        break;
    }

    return addr;
}
开发者ID:thaisdb,项目名称:TCC,代码行数:36,代码来源:qpycore_types.cpp

示例8:

	static QObject *createInstance()
	{
		static QWeakPointer<QObject> instance;
		if (!instance)
			instance = QWeakPointer<QObject>(new qutim_sdk_0_3::ScriptExtensionPlugin);
		return instance.data();
	}
开发者ID:akahan,项目名称:qutim,代码行数:7,代码来源:scriptextensionplugin.cpp

示例9: textStream

//static
void DrKonqi::saveReport(const QString & reportText, QWidget *parent)
{
    if (KCmdLineArgs::parsedArgs()->isSet("safer")) {
        KTemporaryFile tf;
        tf.setSuffix(".kcrash.txt");
        tf.setAutoRemove(false);

        if (tf.open()) {
            QTextStream textStream(&tf);
            textStream << reportText;
            textStream.flush();
            KMessageBox::information(parent, i18nc("@info",
                                                   "Report saved to <filename>%1</filename>.",
                                                   tf.fileName()));
        } else {
            KMessageBox::sorry(parent, i18nc("@info","Could not create a file in which to save the report."));
        }
    } else {
        QString defname = getSuggestedKCrashFilename(crashedApplication());

        QWeakPointer<KFileDialog> dlg = new KFileDialog(defname, QString(), parent);
        dlg.data()->setSelection(defname);
        dlg.data()->setCaption(i18nc("@title:window","Select Filename"));
        dlg.data()->setOperationMode(KFileDialog::Saving);
        dlg.data()->setMode(KFile::File);
        dlg.data()->setConfirmOverwrite(true);
        dlg.data()->exec();

        if (dlg.isNull()) {
            //Dialog is invalid, it was probably deleted (ex. via DBus call)
            //return and do not crash
            return;
        }

        KUrl fileUrl = dlg.data()->selectedUrl();
        delete dlg.data();

        if (fileUrl.isValid()) {
            KTemporaryFile tf;
            if (tf.open()) {
                QTextStream ts(&tf);
                ts << reportText;
                ts.flush();
            } else {
                KMessageBox::sorry(parent, i18nc("@info","Cannot open file <filename>%1</filename> "
                                                         "for writing.", tf.fileName()));
                return;
            }

            if (!KIO::NetAccess::upload(tf.fileName(), fileUrl, parent)) {
                KMessageBox::sorry(parent, KIO::NetAccess::lastErrorString());
            }
        }
    }
}
开发者ID:KDE,项目名称:kde-runtime,代码行数:56,代码来源:drkonqi.cpp

示例10: enableHeader

/**
 * \brief Initialization
 *
 * Initializes the TabsApplet with default parameters
 */
void
TabsApplet::init()
{
    // applet base initialization
    Context::Applet::init();

    // create the header label
    enableHeader( true );
    setHeaderText( i18nc( "Guitar tablature", "Tabs" ) );

    // creates the tab view
    m_tabsView = new TabsView( this );

    // Set the collapse size
    setCollapseOffHeight( -1 );
    setCollapseHeight( m_header->height() );
    setMinimumHeight( collapseHeight() );
    setPreferredHeight( collapseHeight() );

    // create the reload icon
    QAction* reloadAction = new QAction( this );
    reloadAction->setIcon( KIcon( "view-refresh" ) );
    reloadAction->setVisible( true );
    reloadAction->setEnabled( true );
    reloadAction->setText( i18nc( "Guitar tablature", "Reload tabs" ) );
    m_reloadIcon = addLeftHeaderAction( reloadAction );
    m_reloadIcon.data()->setEnabled( false );
    connect( m_reloadIcon.data(), SIGNAL(clicked()), this, SLOT(reloadTabs()) );

    // create the settings icon
    QAction* settingsAction = new QAction( this );
    settingsAction->setIcon( KIcon( "preferences-system" ) );
    settingsAction->setEnabled( true );
    settingsAction->setText( i18n( "Settings" ) );
    QWeakPointer<Plasma::IconWidget> settingsIcon = addRightHeaderAction( settingsAction );
    connect( settingsIcon.data(), SIGNAL(clicked()), this, SLOT(showConfigurationInterface()) );

    m_layout = new QGraphicsLinearLayout( Qt::Vertical );
    m_layout->addItem( m_header );
    m_layout->addItem( m_tabsView );
    setLayout( m_layout );

    // read configuration data and update the engine.
    KConfigGroup config = Amarok::config("Tabs Applet");
    m_fetchGuitar = config.readEntry( "FetchGuitar", true );
    m_fetchBass = config.readEntry( "FetchBass", true );

    Plasma::DataEngine *engine = dataEngine( "amarok-tabs" );
    engine->setProperty( "fetchGuitarTabs", m_fetchGuitar );
    engine->setProperty( "fetchBassTabs", m_fetchBass );
    engine->connectSource( "tabs", this );

    updateInterface( InitState );
}
开发者ID:cancamilo,项目名称:amarok,代码行数:59,代码来源:TabsApplet.cpp

示例11: testCustomNavigationBarContentOwnershipOnPageDeletion

void Ut_MApplicationPage::testCustomNavigationBarContentOwnershipOnPageDeletion() {
    QGraphicsWidget *customNavigationBarContent = new QGraphicsWidget;
    QWeakPointer<QGraphicsWidget> customNavigationBarContentPointer = customNavigationBarContent;

    m_subject->setCustomNavigationBarContent(customNavigationBarContent);

    delete m_subject;
    m_subject = 0;

    QVERIFY(customNavigationBarContentPointer.isNull());
}
开发者ID:arcean,项目名称:libmeegotouch-framework,代码行数:11,代码来源:ut_mapplicationpage.cpp

示例12: addBrowseView

  void Workspace::addBrowseView(QString cubename) {
    /* Close the last browse window if necessary.  */
    if (subWindowList().size()) {
      QWeakPointer<QMdiSubWindow> windowToRemove =
          subWindowList()[subWindowList().size() - 1];

      removeSubWindow(windowToRemove.data());

      delete windowToRemove.data();
    }

    addCubeViewport(cubename);
  }
开发者ID:corburn,项目名称:ISIS,代码行数:13,代码来源:Workspace.cpp

示例13: Q_D

int PasswordDialog::exec()
{
	Q_D(PasswordDialog);
	if (d->eventLoop) // recursive call
		return -1;
	QEventLoop eventLoop;
	d->eventLoop = &eventLoop;
	QWeakPointer<PasswordDialog> guard = this;
	(void) eventLoop.exec();
	d->eventLoop = 0;
	if (guard.isNull())
		return PasswordDialog::Rejected;
	return result();
}
开发者ID:akahan,项目名称:qutim,代码行数:14,代码来源:passworddialog.cpp

示例14: QVERIFY

void SimplePersonSetTest::testConstructorDestructorCreate()
{
    // Create a PersonSet.
    SimplePersonSetPtr personSet = SimplePersonSet::create();
    QVERIFY(!personSet.isNull());

    // Get a QWeakPointer to it, for testing destruction.
    QWeakPointer<PersonSet> weakPtr = QWeakPointer<PersonSet>(personSet.data());

    // Remove the only strong ref.
    personSet.reset();

    // Check the PersonSet was deleted OK
    QVERIFY(personSet.isNull());
    QVERIFY(weakPtr.isNull());
}
开发者ID:KDE,项目名称:ktp-kde,代码行数:16,代码来源:simple-person-set-test.cpp

示例15: documentChanged

void PDFViewer::documentChanged(const QWeakPointer<QtPDF::Backend::Document> newDoc)
{
  if (_counter) {
    QSharedPointer<QtPDF::Backend::Document> doc(newDoc.toStrongRef());
    _counter->setLastPage(doc->numPages());
  }
}
开发者ID:stloeffler,项目名称:texworks-travis-ci,代码行数:7,代码来源:PDFViewer.cpp


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