Qt QML and SOAP
-
wrote on 9 Apr 2011, 05:37 last edited by
Hi there, I'd like to ask regarding the QML Qt and SOAP, that is:
Does the SOAP accessible directly through the QML? If so, is there any example code for me to study it?
And a basic question that keeps bugging me, is Qt QML as strong as the Qt c++ or is it used only for designing the UI only??
Thanks for your attention.
Regards, -
wrote on 9 Apr 2011, 07:57 last edited by
Qt does not support SOAP out of the box. You need to use a 3rd party solution such as "kd-soap":http://www.kdab.com/kd-soap or "gsoap":http://www.cs.fsu.edu/~engelen/soap.html or roll your own.
As for QML it is possible to write complete applications with only QML and javascript some things are accomplished more easily or comfortably in C++ still. It is up to you where you draw the line between what you do in QML/js and what you do in C++ as it depends upon your requirements.
-
wrote on 9 Apr 2011, 08:01 last edited by
Note that combining C++ Qt and QML is quite simple. There is no reason to make it hard on yourself and force yourself to do everything in QML when it is easier to do in C++, especialy if you already have working C++ code lying around.
-
wrote on 5 May 2011, 01:02 last edited by
Thanks for the reply, I had to post phone my job due to my school..The SOAP has been connected successfully to the Qt, now what I need to do is connecting the Qml to the Qt.
Thanks for your reply everyone! -
wrote on 5 May 2011, 07:44 last edited by
OK good. Feel free to come back if you have trouble with integrating C++ with QML and we'll try to help you out. It's not particularly difficult once you see how to do it.
-
wrote on 10 May 2011, 04:16 last edited by
I found a new problem now.. The plan is to insert a username and password through the LogInPage.qml, and when we clicked the login button, I'd lilke to pass the value of username and password to the loginwidget.cpp where I could enter the logInFunction, this is my code:
@//loginwidget
#include "loginwidget.h"
#include "QDebug"
#include "Gsoap/testBinding.nsmap"LoginWidget::LoginWidget()
{}
void LoginWidget::fungsiLogIn(char username, char password){
char output;
if ( clientSoap.ns2__functionLogin(&username,&password,&output) == SOAP_OK)
emit success();else emit failed();
}
@@//main.cpp
#include <QtGUI/QApplication>
#include <QtCore/QCoreApplication>
#include "controllerdeclarativeview.h"
#include "loginwidget.h"
//#include "loginpage.qml"
#include <qdeclarative.h>
#include <QDeclarativeView>
#include <QDeclarativeContext>int main(int argc, char *argv[])
{QApplication app(argc, argv);
qmlRegisterType<LoginWidget>("lib", 1, 0, "LoginWidget");
controllerDeclarativeView w;
w.show();
return app.exec();
}
@@//part of the login.qml
import QtQuick 1.0
import lib 1.0Rectangle
{
id: mainWindow
width: 360; height: 360
...
LoginWidget {
id: aLoginWidget
anchors.centerIn: parent
width: 100; height: 100
color: "red"
onsuccess: console.log("Succeeded")
onfailed: console.log("Failed")
}
...
MouseArea
{
id: mouseareaLogIn
width: 75
height: 26
anchors.rightMargin: 5
anchors.bottomMargin: -6
anchors.fill: parent
onClicked: aLoginWidget.fungsiLogIn(inputLogin,inputPass)
}
@and two errors appear:
'ui::main window' : no appropriate default constructor availableand
unable to recover from previous error; stopping compilation
Any idea how to solved this?
-
wrote on 10 May 2011, 05:57 last edited by
Take a look at the source for the Qt Dev Net client I am writing. I basically take the same approach there. You cna browse the source "here":https://websvn.theharmers.co.uk/listing.php?repname=Codes&path=/public/qtdevnetclient/trunk/ or get a local checkout by doing:
@
svn co https://svn.theharmers.co.uk/svn/codes/public/qtdevnetclient/trunk qtdevnet
@The parts to look at are:
- authenticator.[h,cpp]: This is the C++ class that actually performs the login using QNetworkAccessManager. The Authenticator::login() function is called from the next file...
- main.qml: This is the master qml scene file. When the login button is clicked we call the Authenticator::login() function passing in the username and password contained in the LineEdit items.
- mainwindow.cpp: In the constructor I expose the authenticator C++ object to the QML root context.
It should all be fairly clear but let me know if you need any further help.
-
wrote on 12 May 2011, 06:12 last edited by
I still can't figured it out, here's my code:
@//controllerdeclarative.h
#ifndef CONTROLLERDECLARATIVEVIEW_H
#define CONTROLLERDECLARATIVEVIEW_H#include <QtGui/QWidget>
#include <QtDeclarative/QDeclarativeView>class controllerDeclarativeView : public QWidget
{
Q_OBJECT
public:
explicit controllerDeclarativeView(QWidget *parent = 0);
QDeclarativeView *view;signals:
public slots:
};
#endif // CONTROLLERDECLARATIVEVIEW_H
@@//loginwidget.h
#ifndef LOGINWIDGET_H
#define LOGINWIDGET_H
#include "Gsoap/soaptestBindingProxy.h" //
#include <QtGui/QWidget>
#include <QDeclarativeItem>class LoginWidget:public QWidget
{
Q_OBJECT
public:
LoginWidget();Q_INVOKABLE void fungsiLogIn(char *username,char *password);
signals:
void success();
void fail();private:
testBinding clientSoap;
};#endif // LOGINWIDGET_H
@@//mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QMainWindow>
namespace Ui {
class MainWindow;
}class MainWindow : public QMainWindow
{
Q_OBJECTpublic:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();private:
};
#endif // MAINWINDOW_H
@@//controllerdeclarativeview.cpp
#include "controllerdeclarativeview.h"controllerDeclarativeView::controllerDeclarativeView(QWidget *parent) :
QWidget(parent)
{
this->view=new QDeclarativeView(this);
view->QDeclarativeView::setSource(QUrl::fromLocalFile("mammi_project.qml"));
this->view->QWidget::show();
}
@@//loginwidget.cpp
#include "loginwidget.h"
#include "QDebug"
#include "Gsoap/testBinding.nsmap"LoginWidget::LoginWidget()
{}
void LoginWidget::fungsiLogIn(char username, char password){
char output;
if ( clientSoap.ns2__functionLogin(&username,&password,&output) == SOAP_OK)
{
if (output)
emit success();
else
emit fail();}
}
@@//main.cpp
#include <QtGUI/QApplication>
#include <QtCore/QCoreApplication>
#include "Gsoap/controllerdeclarativeview.h"
#include "loginwidget.h"
//#include "loginpage.qml"
#include <qdeclarative.h>
#include <QDeclarativeView>int main(int argc, char *argv[])
{
QApplication app(argc, argv);qmlRegisterType<LoginWidget>("mod", 1, 0, "LoginWidget");
controllerDeclarativeView w;
w.show();
return app.exec();
}
@@//mainwindow.cpp
#include "mainwindow.h"MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent){
}
MainWindow::~MainWindow()
{}
@@//LogInPage.qml
import QtQuick 1.0
import "mod 1.0"Rectangle
{
id: mainWindow
width: 360; height: 360
Image
{
id: backgroundAbout
source: "comp/pic/background-about.jpg"Text { id: text1 x: 21 y: 118 width: 80 height: 20 text: "UserName:" rotation: 0 font.family: "OCR A Extended" } Text { id: text2 x: 218 y: 207 width: 80 height: 20 text: "PassWord:" rotation: 0 font.family: "OCR A Extended" font.pixelSize: 25 } LoginWidget { id: asd anchors.centerIn: parent width: 50; height: 100 color: "red" onsukses: console.log("login executed") } TextInput { id: inputLogin text: "" x: 0 y: 0 width: 310 height: 22 text: "" opacity: 1 selectionColor: "#ffffff" font.family: "OCR A Extended" } } TextInput { id: inputPass text: "" x: 1 y: 1 width: 310 height: 22 text: "" selectionColor: "#ffffff" font.family: "OCR A Extended" opacity: 1 } Text { id: text3 x: 143 y: 301 width: 80 height: 20 text: "LogIn" font.family: "OCR A Extended" font.pixelSize: 25 MouseArea { id: mouseareaLogIn width: 75 height: 26 anchors.rightMargin: 5 anchors.bottomMargin: -6 anchors.fill: parent onClicked: asd.fungsiLogIn(inputLogin,inputPass) //onClicked: pageModel.pageRequested("MainScreen.qml") } } }
@
Did I miss something?
-
wrote on 12 May 2011, 06:13 last edited by
it's done, I used this link as reference: "http://doc.qt.nokia.com/4.7-snapshot/qtbinding.html":