Problem with QML User Controls [closed]
-
I'm currently writing an App which shall use the CodeProject API, and provide the user the possibility of accessing CP content from their mobile phone.
For completeness, here's the header of the Login class:
@#ifndef LOGIN_H
#define LOGIN_H#include <QObject>
#include <QtNetwork>
#include <QByteArray>
#include <QDebug>
#include <API/bearertoken.h>class Login : public QObject
{
Q_OBJECT
private:
QNetworkAccessManager linkNetworkAccess;
static BearerToken cpBearerToken;private slots:
void onLinkAnswered(QNetworkReply *reply);public:
explicit Login(QObject *parent = 0);
~Login();
Q_INVOKABLE void link(QString username, QString password);Q_INVOKABLE BearerToken getBearerToken();
signals:
void linkSuccess(BearerToken token);
void linkFailed();
};#endif // LOGIN_H
@Now, since the login only happens once (at the very beginning) I wanted to write some sort of user control where the user enters the email address and password.
This is the "LoginScreen.qml" I came up with:@import QtQuick 2.0
import QtQuick.Controls 1.2CPRectangle {
width: childrenRect.width + 20
height: childrenRect.height + 20signal login(string email, string password)
Column {
anchors.centerIn: parent
spacing: 16
Column {
spacing: 4
CPText { text: "Email" }
TextField {
id:emailField
placeholderText: qsTr("Enter your email address")
}
}
Column {
spacing: 4
CPText { text: "Password" }
TextField {
id:passwordField
echoMode:Password
placeholderText: qsTr("Enter Password")
}
}
Row {
spacing: 16
anchors.horizontalCenter: parent.horizontalCenter
Button { text: "Login"; onClicked: login(emailField.text, passwordField.text) }
}
}
}
@
It looks good in the Designer view:
!http://www.codeproject.com/script/Membership/Uploads/8888914/1.png!Now I want to include it in my main.qml as following:
@import QtQuick 2.0
import com.mbertschi.CPAPI 1.0CPRectangle {
id:background
width: 360
height: 360
LoginControl{
id:loginScreen
anchors.centerIn: parent
onLogin:{
cpLogin.link(email, password)
}
}Login{ id:cpLogin onLinkSuccess: { loginScreen.visible = false; } }
}
@But the designer view shows only a blank orange area:
!http://www.codeproject.com/script/Membership/Uploads/8888914/2.png!
Does anyone have an idea what the error could be?
cheers,
Marco -
Hi,
Please edit the links that points to a valid address.
Now coming to LoginControl and Login components, can you try providing width and height to them ?
-
Thank you very much for the answer.
I fixed the links.Providing width & height doesn't bring anything.
-
Is the dark yellow rectangle in second image CPRectangle ?
-
Yes, but the one placed in main.qml.
I found the error meanwhile:
on top of the LoginScreen.qml I wrote
@import QtQuick.Controls 1.2@
This was wrong because my installed version has V 1.1 of the QtQuickl controls included, so I changed it to
@import QtQuick.Controls 1.2@
and now everything works fine - I wonder why the Button and TextFields were showing properly in the Design View of LoginScreen.qml, though.