Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Problem with QML User Controls [closed]
Forum Updated to NodeBB v4.3 + New Features

Problem with QML User Controls [closed]

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mabertschi
    wrote on last edited by
    #1

    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.2

    CPRectangle {
    width: childrenRect.width + 20
    height: childrenRect.height + 20

    signal 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.0

    CPRectangle {
    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

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      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 ?

      157

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mabertschi
        wrote on last edited by
        #3

        Thank you very much for the answer.
        I fixed the links.

        Providing width & height doesn't bring anything.

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          Is the dark yellow rectangle in second image CPRectangle ?

          157

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mabertschi
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved