Hi,
What I am trying to do here is create a communication from the QML front end to the C++ backend.
I have a class in C++ named Dialpad with corresponding .h and .c files you can see here:
#ifndef DIALPAD_H
#define DIALPAD_H
#include <QObject>
{
Q_OBJECT
public:
explicit Dialpad
(QObject *parent
= 0);
signals:
void dialSignal
(const QString &inNumberToDial
);
public slots:
void dialSlot
(const QString &inNumberToDial
);
};
#endif // DIALPAD_H
#include "dialpad.h"
#include <QDebug>
{
}
/**
Name: dialSlot().
Description: this function is called from QML front end and sends the number to be dialed.
It will then emit the number to any functions who may need to number.
@param inNumberToDial this is the number that will be dialed
@return void
*/
void Dialpad
::dialSlot(const QString &inNumberToDial
) {
qDebug() << "Number recieved from QML frontend: " << inNumberToDial << endl;
emit dialSignal(inNumberToDial);
}
#ifndef DIALPAD_H
#define DIALPAD_H
#include <QObject>
class Dialpad : public QObject
{
Q_OBJECT
public:
explicit Dialpad(QObject *parent = 0);
signals:
void dialSignal(const QString &inNumberToDial);
public slots:
void dialSlot(const QString &inNumberToDial);
};
#endif // DIALPAD_H
#include "dialpad.h"
#include <QDebug>
Dialpad::Dialpad(QObject *parent) : QObject(parent)
{
}
/**
Name: dialSlot().
Description: this function is called from QML front end and sends the number to be dialed.
It will then emit the number to any functions who may need to number.
@param inNumberToDial this is the number that will be dialed
@return void
*/
void Dialpad::dialSlot(const QString &inNumberToDial)
{
qDebug() << "Number recieved from QML frontend: " << inNumberToDial << endl;
emit dialSignal(inNumberToDial);
}
To copy to clipboard, switch view to plain text mode
I have a main.cpp that is doing the following:
#include <QtGui/QApplication>
#include <QDeclarativeView>
#include <QDeclarativeContext>
#include <QDebug>
#include <QList>
#include <QDeclarativeEngine>
#include <QDeclarativeComponent>
#include <QGraphicsDropShadowEffect>
#include "callinfo/callsonholdmodel.h"
#include "dialpad/dialpad.h"
int main(int argc, char *argv[])
{
qmlRegisterType<Dialpad>("DialpadPkg", 1, 0, "aDialpad");
QDeclarativeView view;
QDeclarativeContext *ctxt = view.rootContext();
//ignore the setContext, this was for something else
ctxt
->setContextProperty
("callsonholdModel",
QVariant::fromValue(callsonholdList
));
view.
setSource(QUrl("qrc:qml/background.qml"));
view.show();
return a.exec();
}
#include <QtGui/QApplication>
#include <QDeclarativeView>
#include <QDeclarativeContext>
#include <QDebug>
#include <QList>
#include <QDeclarativeEngine>
#include <QDeclarativeComponent>
#include <QGraphicsDropShadowEffect>
#include "callinfo/callsonholdmodel.h"
#include "dialpad/dialpad.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
qmlRegisterType<Dialpad>("DialpadPkg", 1, 0, "aDialpad");
QDeclarativeView view;
QDeclarativeContext *ctxt = view.rootContext();
//ignore the setContext, this was for something else
ctxt->setContextProperty("callsonholdModel", QVariant::fromValue(callsonholdList));
view.setSource(QUrl("qrc:qml/background.qml"));
view.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Now when I try to import the object DialpadPkg so I can use aDialpad item to send a message from QML to C++ with the aDialpad.dialSlot("12345"); it says aDialpad is not a type, and it also says it can't import DialpadPkg 1.0
here is the background.qml
import Qt 4.7
import "Dialpad"
import "callinfo"
import "buttontray"
import "calendar"
import DialpadPkg 1.0 //doesn't work
Rectangle {
//doesn't work
aDialpad
{
id: interfaceDialpad
//interfaceDialpad.dialSlot("12345")
}
...
...
import Qt 4.7
import "Dialpad"
import "callinfo"
import "buttontray"
import "calendar"
import DialpadPkg 1.0 //doesn't work
Rectangle {
//doesn't work
aDialpad
{
id: interfaceDialpad
//interfaceDialpad.dialSlot("12345")
}
...
...
To copy to clipboard, switch view to plain text mode
The directory stucture is the following:
MainProject/main.cpp
background.qml
MainProject/Dialpad/dialpad.cpp
dialpad.h
Any ideas?
Thanks
Bookmarks