[Solved]Specific signals/slots problem.
-
Hey all,
New to the forums here at Qt Project. Been on the BlackBerry Developer forums for a short time and trying to learn Qt among other things to develop apps on BlackBerry (and perhaps other mobiles later when I get the hang of things). Anyways, I wrote a simple app to test out Signals and Slots with C++ and QML.
I have no idea what is wrong with my QObject::connect function. It doesn't seem to be sending or triggering anything. I think I have all the necessary code tweaks to get the connect to work, but.... I'm missing something...
Any help would be greatly appreciated and thanks in advance.
--Edit--
Didn't include the main.cpp file because it just creates a new class object..hpp file:
@// Default empty project template
#ifndef Testme_HPP_
#define Testme_HPP_#include <QObject>
namespace bb { namespace cascades { class Application; }}
namespace bb { namespace cascades { class TouchEvent; }}
namespace bb { namespace cascades { class Container; }}
namespace bb { namespace cascades { class ImageView; }}
namespace bb { namespace cascades { class Label; }}/*!
- @brief Application pane object
Use this object to create and init app UI, to create context objects, to register the new meta types etc.
/
class Testme : public QObject
{
Q_OBJECT
public:
Testme(bb::cascades::Application app);
virtual ~Testme() {}
public slots:
void handleTouch(bb::cascades::TouchEvent tEvent);
private:
bb::cascades::Container rootContainer;
bb::cascades::Label rootLabel;
bb::cascades::ImageView* imgView;
};#endif /* Testme_HPP_ */
@.cpp file:
@// Default empty project template
#include "Testme.hpp"#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/Container>
#include <bb/cascades/TouchEvent>
#include <bb/cascades/ImageView>
#include <bb/cascades/AbstractPane>using namespace bb::cascades;
Testme::Testme(bb::cascades::Application *app)
: QObject(app)
{
// create scene document from main.qml asset
// set parent to created document to ensure it exists for the whole application lifetime
QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
QmlDocument *qml2 = QmlDocument::create("asset:///Testingme.qml").parent(this);// create root object for the UI AbstractPane *root = qml->createRootObject<AbstractPane>(); // set created root object as a scene app->setScene(root); if (!qml2->hasErrors()) { rootContainer = qml2->createRootObject<Container>(); if (rootContainer) { imgView = rootContainer->findChild<ImageView*>("imgView"); if (imgView) { bool res = QObject::connect(imgView, SIGNAL(touch(bb::cascades::TouchEvent*)), this, SLOT(handleTouch(bb::cascades::TouchEvent*))); Q_ASSERT(res); Q_UNUSED(res); fprintf(stderr, "Height: %f and width: %f\n", imgView->preferredHeight(), imgView->preferredWidth()); } else { fprintf(stderr, "No ImageView\n"); } } else { fprintf(stderr, "No root container\n"); } } else { fprintf(stderr, "QML2 has errors\n"); }
}
void Testme::handleTouch(bb::cascades::TouchEvent *tEvent)
{
fprintf(stderr, "Touch Touch Touch\n");
}@main.qml file:
@// Default empty project template
import bb.cascades 1.0// creates one page with a label
Page {
Container {
objectName: "mainContainer"
layout: StackLayout {}
Label {
objectName: "rootLabel"
text: qsTr("Hello World")
}Testingme { id: testingMe } }
}@
Testingme.qml file:
@import bb.cascades 1.0
Container {
objectName: "rootContainer"
horizontalAlignment: HorizontalAlignment.Center
verticalAlignment: VerticalAlignment.Center
background: Color.create ("#262626")ImageView { objectName: "imgView" imageSource: "asset:///belligerent.png" preferredHeight: 200 preferredWidth: 200 }
}
@ -
Problem:
[quote author="jalue" date="1363015067"]Hey all,New to the forums here at Qt Project. Been on the BlackBerry Developer forums for a short time and trying to learn Qt among other things to develop apps on BlackBerry (and perhaps other mobiles later when I get the hang of things). Anyways, I wrote a simple app to test out Signals and Slots with C++ and QML.
*I have no idea what is wrong with my QObject::connect function. It doesn't seem to be sending or triggering anything. I think I have all the necessary code tweaks to get the connect to work, but.... I'm missing something... *
Any help would be greatly appreciated and thanks in advance.
[/quote]
I guess Bold tags don't work in quotes.Solution:
Should've used the qml object for making changes and setting the QObject::connect, even though the ImageView is in qml2.