本文整理汇总了C++中QObject类的典型用法代码示例。如果您正苦于以下问题:C++ QObject类的具体用法?C++ QObject怎么用?C++ QObject使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updateText
void MultiSlidingValueDialog::updateText(int value)
{
int i;
QObject *slider;
if (sender() != NULL) {
for (i = 0; i < mSliders.count(); i++) {
if (mSliders.at(i) == sender()) {
break;
}
}
slider = sender();
} else {
i = mSliders.count() - 1;
slider = mSliders.at(i);
}
QString name = slider->objectName();
QString textVal = QString::number(value);
mLabels[i]->setText(mText.arg(name, textVal));
}
示例2: fileAction
void LuaAVConsole :: fileAction() {
QObject *s = sender();
const char *name = s->objectName().toStdString().data();
const char *idx = strchr(name, ':')+1;
int i = 0;
sscanf(idx, "%d", &i);
const char *filename = getFilenameWithScriptIndex(i);
if(strncmp(name, "close", strlen("close")) == 0) {
lua::call(luaav_getstate(luaav_app_state()), "fileclose", filename);
}
else if(strncmp(name, "reload", strlen("reload")) == 0) {
lua::call(luaav_getstate(luaav_app_state()), "fileopen", filename);
}
else if(strncmp(name, "edit", strlen("edit")) == 0) {
lua::call(luaav_getstate(luaav_app_state()), "fileedit", filename);
}
}
示例3: QKeyEvent
/**
* Forward the QKeyEvent to the QsciScintilla base class.
* Under Gnome on Linux with Qscintilla versions < 2.4.2 there is a bug with the
* autocomplete
* box that means the editor loses focus as soon as it the box appears. This
* functions
* forwards the call and sets the correct flags on the resulting window so that
* this does not occur
*/
void ScriptEditor::forwardKeyPressToBase(QKeyEvent *event) {
// Hack to get around a bug in QScitilla
// If you pressed ( after typing in a autocomplete command the calltip does
// not appear, you have to delete the ( and type it again
// This does that for you!
if (event->text() == "(") {
QKeyEvent *backspEvent =
new QKeyEvent(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier);
QKeyEvent *bracketEvent = new QKeyEvent(*event);
QsciScintilla::keyPressEvent(bracketEvent);
QsciScintilla::keyPressEvent(backspEvent);
delete backspEvent;
delete bracketEvent;
}
QsciScintilla::keyPressEvent(event);
// Only need to do this for Unix and for QScintilla version < 2.4.2. Moreover,
// only Gnome but I don't think we can detect that
#ifdef Q_OS_LINUX
#if QSCINTILLA_VERSION < 0x020402
// If an autocomplete box has surfaced, correct the window flags.
// Unfortunately the only way to
// do this is to search through the child objects.
if (isListActive()) {
QObjectList children = this->children();
QListIterator<QObject *> itr(children);
// Search is performed in reverse order as we want the last one created
itr.toBack();
while (itr.hasPrevious()) {
QObject *child = itr.previous();
if (child->inherits("QListWidget")) {
QWidget *w = qobject_cast<QWidget *>(child);
w->setWindowFlags(Qt::ToolTip | Qt::WindowStaysOnTopHint);
w->show();
break;
}
}
}
#endif
#endif
}
示例4: childRemoved
void KviWindow::childRemoved(QWidget * pObject)
{
pObject->removeEventFilter(this);
if(pObject == m_pFocusHandler)
m_pFocusHandler = NULL;
if(pObject == m_pLastFocusedChild)
m_pLastFocusedChild = NULL;
QList<QObject *> list = pObject->children();
for(QList<QObject *>::Iterator it = list.begin(); it != list.end(); ++it)
{
QObject * pObj = *it;
if(pObj->isWidgetType())
{
childRemoved((QWidget *)pObj);
}
}
}
示例5: loader
/*
* This is test case that loads dependency automatically. Both success and fail case.
*/
void TestCreateFile::testLoadDependency()
{
QQmlEngine *engine = new QQmlEngine;
QmcLoader loader(engine);
loader.setLoadDependenciesAutomatically(false);
QQmlComponent *c = NULL;
c = loader.loadComponent(tempDirPath(SUB_ITEM_WITH_SCRIPT_QMC));
QVERIFY(!c);
loader.setLoadDependenciesAutomatically(true);
c = loader.loadComponent(tempDirPath(SUB_ITEM_WITH_SCRIPT_QMC));
QVERIFY(c);
QObject *obj = c->create();
QVariant var = obj->property("height");
QVERIFY(!var.isNull());
QVERIFY(var.toInt() == 40);
delete obj;
delete c;
delete engine;
}
示例6: createFilter
KoFilter* KoFilterEntry::createFilter(KoFilterChain* chain, QObject* parent)
{
KLibFactory *factory = qobject_cast<KLibFactory *>(m_loader->instance());
if (!factory) {
warnMain << m_loader->errorString();
return 0;
}
QObject* obj = factory->create<KoFilter>(parent);
if (!obj || !obj->inherits("KoFilter")) {
delete obj;
return 0;
}
KoFilter* filter = static_cast<KoFilter*>(obj);
filter->m_chain = chain;
return filter;
}
示例7: FROM_UTF8
void HistoWidget::buttonPressedX()
{
if (!mpModel) return;
// mpObjectX = CCopasiSelectionDialog::getObjectSingle(this, CQSimpleSelectionTree::NUMERIC, mpObjectX);
//mpObjectX = CCopasiSelectionDialog::getObjectSingle(this, CQSimpleSelectionTree::PLOT_OBJECT, mpObjectX);
std::vector< const CCopasiObject * > oldSelection;
if (mpObjectX)
oldSelection.push_back(mpObjectX);
std::vector< const CCopasiObject * > objects =
CCopasiSelectionDialog::getObjectVector(this,
CQSimpleSelectionTree::NumericValues,
&oldSelection);
if (objects.size() && objects[0])
{
mpObjectX = objects[0];
mpEditVariable->setText(FROM_UTF8(mpObjectX->getObjectDisplayName()));
mpEditTitle->setText("Histogram: " + FROM_UTF8(mpObjectX->getObjectDisplayName()));
}
else
{
mpObjectX = NULL;
mpEditVariable->setText("");
mpEditTitle->setText("Histogram");
}
//check if more than one object was selected...
if (objects.size() > 1)
{
CQPlotSubwidget * pParent;
QObject* tmp = this;
while (!(pParent = dynamic_cast< CQPlotSubwidget * >(tmp)) && this)
tmp = tmp->parent();
if (pParent) //tell the parent to create the remaining histogram descriptions.
pParent->createHistograms(objects, mpEditIncrement->text().toDouble());
}
}
示例8: Engine
void EngineTest::engineErrorHandlerSkipTest(){
Engine* engine = new Engine(new QQmlEngine);
bool isWarning = false;
bool isError = false;
QObject::connect(engine, &Engine::applicationWarning, [&isWarning, this](QJSValue){
isWarning = true;
});
QObject::connect(engine, &Engine::applicationError, [&isError, this](QJSValue){
isError = true;
});
QObject livecvStub;
livecvStub.setProperty("engine", QVariant::fromValue(engine));
engine->engine()->rootContext()->setContextProperty("engine", engine);
engine->engine()->rootContext()->setContextProperty("livecv", &livecvStub);
QObject* obj = engine->createObject(
"import QtQuick 2.3\n import base 1.0\n "
"Item{\n"
"id: root;\n"
"ErrorHandler{\n"
"onError: skip(e);\n"
"onWarning: skip(e);\n"
"}\n"
"EngineTestStub{\n"
"Component.onCompleted: {\n"
"throwJsWarning();"
"throwJsError();"
"}\n"
"}\n"
"}\n",
0,
QUrl::fromLocalFile("enginetest.qml")
);
QVERIFY(obj != 0);
QCoreApplication::processEvents();
QVERIFY(isWarning);
QVERIFY(isError);
}
示例9: connectFunctions
void connectFunctions(ChildrenInterface* children) {
Q_ASSERT( m_engine );
Q_ASSERT( ! m_engine->hasUncaughtException() );
QString eval;
QScriptValue global = m_engine->globalObject();
QHashIterator< QString, ChildrenInterface::Options > it( children->objectOptions() );
while(it.hasNext()) {
it.next();
if( it.value() & ChildrenInterface::AutoConnectSignals ) {
QObject* sender = children->object(it.key());
if( ! sender )
continue;
QScriptValue obj = m_engine->globalObject().property(it.key());
if( ! obj.isQObject() )
continue;
const QMetaObject* mo = sender->metaObject();
const int count = mo->methodCount();
for(int i = 0; i < count; ++i) {
QMetaMethod mm = mo->method(i);
#if QT_VERSION < 0x050000
const QString signature = mm.signature();
#else
const QString signature = mm.methodSignature();
#endif
const QString name = signature.left(signature.indexOf('('));
if( mm.methodType() == QMetaMethod::Signal ) {
QScriptValue func = global.property(name);
if( ! func.isFunction() ) {
//qrossdebug( QString("EcmaScript::connectFunctions No function to connect with %1.%2").arg(it.key()).arg(name) );
continue;
}
qrossdebug( QString("EcmaScript::connectFunctions Connecting with %1.%2").arg(it.key()).arg(name) );
eval += QString("try { %1.%2.connect(%3); } catch(e) { print(e); }\n").arg(it.key()).arg(name).arg(name);
}
}
}
}
Q_ASSERT( ! m_engine->hasUncaughtException() );
if( ! eval.isNull() ) {
m_engine->evaluate(eval);
Q_ASSERT( ! m_engine->hasUncaughtException() );
}
}
示例10: TEST_FILE
void TestSimpleQmlLoad::loadComponent1()
{
QQmlEngine *engine = new QQmlEngine;
const QString TEST_FILE(":/testqml/testcomponent1.qml");
QQmlComponent* component = load(engine, TEST_FILE);
QVERIFY(component);
QObject *myObject = component->create();
QVERIFY(myObject != NULL);
QVariant var = myObject->property("c1");
QVERIFY(!var.isNull());
QVariant ret;
QMetaObject::invokeMethod(myObject, "getSubWidth1", Q_RETURN_ARG(QVariant, ret));
QVERIFY(ret.toInt() == 10);
delete component;
delete engine;
}
示例11: updateBackgrounds
void KviWindow::updateBackgrounds(QObject * pObject)
{
if(!pObject)
pObject = this;
QList<QObject *> list = pObject->children();
if(list.count())
{
for(QList<QObject *>::Iterator it = list.begin(); it != list.end(); ++it)
{
QObject * pChild = *it;
if(pChild->metaObject()->indexOfProperty("TransparencyCapable") != -1)
{
//if (child->isWidgetType())
((QWidget *)pChild)->update();
}
updateBackgrounds(pChild);
}
}
}
示例12: waitForEvent
void WaitForEventTest::testWaitEnded() {
QObject parentObject;
WaitForEvent waitForEvent(&parentObject, QEvent::ChildAdded);
waitForEvent.setActive(true);
//WaitFor* must be registered in order to be used with QSignalSpy
int waitForStarType = qRegisterMetaType<WaitFor*>("WaitFor*");
QSignalSpy waitEndedSpy(&waitForEvent, SIGNAL(waitEnded(WaitFor*)));
QObject* childObject = new QObject();
childObject->setParent(&parentObject);
QVERIFY(waitForEvent.conditionMet());
QCOMPARE(waitEndedSpy.count(), 1);
QVariant argument = waitEndedSpy.at(0).at(0);
QCOMPARE(argument.userType(), waitForStarType);
QCOMPARE(qvariant_cast<WaitFor*>(argument), &waitForEvent);
}
示例13: fields
QSqlRecord DbSchema::sqlRecord(QObject *table, bool lowercase_field_names)
{
QSqlRecord ret;
QQmlListReference fields(table, "fields", m_eventPlugin->qmlEngine());
for (int i = 0; i < fields.count(); ++i) {
QObject *field = fields.at(i);
QString name = field->property("name").toString();
if(lowercase_field_names)
name = name.toLower();
QVariant typev = field->property("type");
QObject *type = typev.value<QObject*>();
QF_ASSERT(type != nullptr, "Internal error: Cannot get field type", return QSqlRecord());
QByteArray type_name = type->property("metaTypeName").toString().toLatin1();
QSqlField fld(name, QVariant::nameToType(type_name.constData()));
ret.append(fld);
//qfInfo() << type << "name:" << name << "type:" << type_name;
}
return ret;
}
示例14: while
static const sipTypeDef *sipSubClass_QHelpEngineCore(void **sipCppRet)
{
QObject *sipCpp = reinterpret_cast<QObject *>(*sipCppRet);
const sipTypeDef *sipType;
#line 37 "/Users/ktaylora/PLJV/tillage_likelihood_model/gui/PyQt4/sip/QtHelp/qhelpenginecore.sip"
static struct class_graph {
const char *name;
sipTypeDef **type;
int yes, no;
} graph[] = {
{sipName_QHelpIndexWidget, &sipType_QHelpIndexWidget, -1, 1},
{sipName_QHelpContentWidget, &sipType_QHelpContentWidget, -1, 2},
{sipName_QHelpContentModel, &sipType_QHelpContentModel, -1, 3},
{sipName_QHelpIndexModel, &sipType_QHelpIndexModel, -1, 4},
{sipName_QHelpSearchResultWidget, &sipType_QHelpSearchResultWidget, -1, 5},
{sipName_QHelpEngineCore, &sipType_QHelpEngineCore, 8, 6},
{sipName_QHelpSearchQueryWidget, &sipType_QHelpSearchQueryWidget, -1, 7},
{sipName_QHelpSearchEngine, &sipType_QHelpSearchEngine, -1, -1},
{sipName_QHelpEngine, &sipType_QHelpEngine, -1, -1},
};
int i = 0;
sipType = 0;
do
{
struct class_graph *cg = &graph[i];
if (cg->name != NULL && sipCpp->inherits(cg->name))
{
sipType = *cg->type;
i = cg->yes;
}
else
i = cg->no;
}
while (i >= 0);
#line 315 "/Users/ktaylora/PLJV/tillage_likelihood_model/gui/PyQt4/QtHelp/sipQtHelpcmodule.cpp"
return sipType;
}
示例15: setThreadData_helper
void QObject::setThreadData_helper(QThreadData *currentData, QThreadData *targetData)
{
// move posted events
int eventsMoved = 0;
for (int i = 0; i < currentData->postEventList.size(); ++i) {
const QPostEvent &postedEvent = currentData->postEventList.at(i);
if (! postedEvent.event) {
continue;
}
if (postedEvent.receiver == this) {
// move this post event to the targetList
targetData->postEventList.addEvent(postedEvent);
const_cast<QPostEvent &>(postedEvent).event = 0;
++eventsMoved;
}
}
if (eventsMoved > 0 && targetData->eventDispatcher) {
targetData->canWait = false;
targetData->eventDispatcher->wakeUp();
}
// the current emitting thread shouldn't restore currentSender after calling moveToThread()
if (m_currentSender) {
m_currentSender->ref = 0;
}
m_currentSender = 0;
// set new thread data
targetData->ref();
QThreadData *threadData = m_threadData.exchange(targetData);
threadData->deref();
for (int k = 0; k < m_children.size(); ++k) {
QObject *child = m_children.at(k);
child->setThreadData_helper(currentData, targetData);
}
}