PDA

View Full Version : Log In Page



chronoski
16th May 2011, 11:28
Hello, I'd like to ask question regarding connecting the QML to cpp, my goal is to send parameter from QML in forms of username and password to cpp, the cpp itself is connected with the GSoap. If the results return true, then the user can move to another page and if wrong username and password were send, nothing will happen; but at the mean time, I'd just show some text at the console screen. This is my code, please give me a clue of what i was lack at.

//LogInPage
import QtQuick 1.0
import "comp"

Rectangle
{
id: mainWindow
width: 360; height: 360
signal dataRequired(string msg,string msg);
function success() {console.log("connection done")}
function fail() {console.log("fail")
Image
{
id: backgroundAbout
source: "comp/pic/background-about.jpg"

Text {
id: text1
x: 21
y: 118
width: 80
height: 20
text: "UserName:"
font.family: "OCR A Extended"
font.pixelSize: 24
}

Text {
id: text2
x: 218
y: 207
width: 80
height: 20
text: "PassWord:"
font.family: "OCR A Extended"
font.pixelSize: 25
}

TextInput
{
id: inputLogin
text: ""
x: 0
y: 0
width: 310
height: 22
selectionColor: "#ffffff"
font.family: "OCR A Std"
}
}

Rectangle {
id: rectangle2
x: 13
y: 234
width: 310
height: 22
color: "#eecfcf"
border.color: "#995757"
TextInput {
id: inputPass
text: ""
x: 1
y: 1
width: 310
height: 22
selectionColor: "#ffffff"
font.family: "OCR A Extended"
opacity: 1
}
opacity: 0.2

Text {
id: text3
x: 143
y: 301
width: 80
height: 20
text: "LogIn"
font.family: "OCR A Extended"
font.pixelSize: 25
MouseArea
{
id: mouseareaLogIn
anchors.fill: parent
onPressed:
{
myObject.fungsiLogIn(inputLogin.text, inputPass.text}
}
}
}
}



//main.cpp
#include "mainwindow.h"
//#include "ui_mainwindow.h"
#include <qdeclarative.h>
#include <QDeclarativeView>
#include "loginwidget.h"
#include <QDebug>

#include <QtCore/QCoreApplication>
#include <QtDeclarative/QDeclarativeEngine>
#include <QtDeclarative/QDeclarativeComponent>
#include <QtDeclarative/QDeclarativeView>
#include <QtDeclarative/QDeclarativeContext>
#include <QtCore/QVariant>
#include <QtCore/QString>
#include <QtCore/QMetaObject>
#include "mainwindow.h"



MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)

{
// QDeclarativeView view;
this->login= new LoginWidget();
this->view= new QDeclarativeView(this);

view->QDeclarativeView::setSource(QUrl::fromLocalFile("LogInPage.qml"));
view->engine()->rootContext()->setContextProperty("myObject",&login);
setCentralWidget(view);
this->show();

}

MainWindow::~MainWindow()
{

}

void MainWindow::test(char *username, char *password)
{
qDebug()<<" Passing done";
}



//mainwindow.cpp
#include <QtGUI/QApplication>
#include <QtCore/QCoreApplication>
#include "loginwidget.h"
//#include "loginpage.qml"
#include <qdeclarative.h>
#include <QDeclarativeView>
#include "mainwindow.h"

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainWindow mainwindow;
mainwindow.show();

return app.exec();
}



//loginwidget.cpp
#include "loginwidget.h"
#include "QDebug"
#include "Gsoap/testBinding.nsmap"
#include <QDeclarativeView>

LoginWidget::LoginWidget()
{

}

void LoginWidget::fungsiLogIn(char *username, char *password){
char *output;

if ( clientSoap.ns2__functionLogin(*&username,*&password,*&output) == SOAP_OK)
{
if (output)
{
emit sukses();
}
else
{
emit gagal();
}

}


Thank you for the aid.

Regards,

wysota
17th May 2011, 01:31
Not to be rude but do you expect us to analyze and debug your code for you? You didn't even say how this code misbehaves with what you expect from it.

chronoski
20th May 2011, 03:28
Sorry, I didn't mean to do so. I should have ask a more specific question. But by the way, it had been solved now, this is the link, just in case if anyone would want it: http://doc.qt.nokia.com/4.7-snapshot/qtbinding.html