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:

Qt Code:
  1. #ifndef DIALPAD_H
  2. #define DIALPAD_H
  3.  
  4. #include <QObject>
  5.  
  6. class Dialpad : public QObject
  7. {
  8. Q_OBJECT
  9. public:
  10. explicit Dialpad(QObject *parent = 0);
  11.  
  12.  
  13. signals:
  14. void dialSignal(const QString &inNumberToDial);
  15. public slots:
  16. void dialSlot(const QString &inNumberToDial);
  17.  
  18.  
  19. };
  20.  
  21. #endif // DIALPAD_H
  22.  
  23. #include "dialpad.h"
  24. #include <QDebug>
  25.  
  26. Dialpad::Dialpad(QObject *parent) : QObject(parent)
  27. {
  28.  
  29.  
  30. }
  31.  
  32.  
  33.  
  34. /**
  35.   Name: dialSlot().
  36.   Description: this function is called from QML front end and sends the number to be dialed.
  37.   It will then emit the number to any functions who may need to number.
  38.   @param inNumberToDial this is the number that will be dialed
  39.   @return void
  40.   */
  41. void Dialpad::dialSlot(const QString &inNumberToDial)
  42. {
  43.  
  44. qDebug() << "Number recieved from QML frontend: " << inNumberToDial << endl;
  45. emit dialSignal(inNumberToDial);
  46.  
  47. }
To copy to clipboard, switch view to plain text mode 

I have a main.cpp that is doing the following:
Qt Code:
  1. #include <QtGui/QApplication>
  2.  
  3. #include <QDeclarativeView>
  4. #include <QDeclarativeContext>
  5. #include <QDebug>
  6. #include <QList>
  7.  
  8. #include <QDeclarativeEngine>
  9. #include <QDeclarativeComponent>
  10. #include <QGraphicsDropShadowEffect>
  11.  
  12. #include "callinfo/callsonholdmodel.h"
  13. #include "dialpad/dialpad.h"
  14.  
  15. int main(int argc, char *argv[])
  16. {
  17. QApplication a(argc, argv);
  18.  
  19.  
  20. qmlRegisterType<Dialpad>("DialpadPkg", 1, 0, "aDialpad");
  21.  
  22.  
  23. QDeclarativeView view;
  24. QDeclarativeContext *ctxt = view.rootContext();
  25. //ignore the setContext, this was for something else
  26. ctxt->setContextProperty("callsonholdModel", QVariant::fromValue(callsonholdList));
  27.  
  28. view.setSource(QUrl("qrc:qml/background.qml"));
  29. view.show();
  30.  
  31.  
  32. return a.exec();
  33. }
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

Qt Code:
  1. import Qt 4.7
  2. import "Dialpad"
  3. import "callinfo"
  4. import "buttontray"
  5. import "calendar"
  6. import DialpadPkg 1.0 //doesn't work
  7.  
  8.  
  9.  
  10.  
  11. Rectangle {
  12.  
  13.  
  14. //doesn't work
  15. aDialpad
  16. {
  17. id: interfaceDialpad
  18.  
  19. //interfaceDialpad.dialSlot("12345")
  20.  
  21. }
  22. ...
  23. ...
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