Results 1 to 18 of 18

Thread: Using QDeclarativeView::Show()

  1. #1
    Join Date
    May 2011
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Symbian S60 Maemo/MeeGo

    Unhappy Using QDeclarativeView::Show()

    Hello all,

    i am making a QML application for symbian devices which has a very rich GUI at the same time all the data is coming from web services in form a xml.

    So what i have done is my all parsing and logic engines are written in c++ and the UI is written in QML. Now i am facing some problems in that.

    When i start the application i make a QNetworkAccessManager get request to get the initial data to show. At that time i load a main.qml file which only have a wait indicator.

    Now when the asynchronous get method completes inside my slot GotNetworkReply, i am starting to parse the xml response and then i want to show another QML view for that i use the following code:

    Qt Code:
    1. QDeclarativeView homeScreenView;
    2. homeScreenView.SetSource("my QML path");
    3. homeScreenView.Show();
    To copy to clipboard, switch view to plain text mode 
    I get no error but my homescreen QML file doesnt shows up, can any body help me what wrong i am doing or what's the other approach to update the data in QML from C++.

    Regards
    Ronald

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Using QDeclarativeView::Show()

    Try using QUrl::fromLocalFile(). And make sure the file exists (QFile::exists()) first.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    frankiefrank (3rd October 2011)

  4. #3
    Join Date
    May 2011
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Symbian S60 Maemo/MeeGo

    Default Re: Using QDeclarativeView::Show()

    hello wysota

    thanks for your attention and the code i pasted there was just a test code, because i was using QUrl::fromLocalfile().

    Following is the exact code i am using:

    Qt Code:
    1. QFile file("qml/HyBridApp/homescreen.qml");
    2. if(file.exists())
    3. {
    4. QDeclarativeView homeScreenView;
    5. homeScreenView.setSource(QUrl::fromLocalFile("qml/HyBridApp/homescreen.qml"));
    6. homeScreenView.showFullScreen();
    7. }
    8. else
    9. {
    10. qDebug()<<"file doesnt exists";
    11. }
    To copy to clipboard, switch view to plain text mode 

    There is no error but homescreen.qml doesnt comes up. :-(

    Regards

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Using QDeclarativeView::Show()

    Whats the contents of the qml file?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #5
    Join Date
    May 2011
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Symbian S60 Maemo/MeeGo

    Default Re: Using QDeclarativeView::Show()

    its just a simple rectangle, as of once the view shows up i will add the actual UI:

    Qt Code:
    1. Rectangle {
    2. width: 360
    3. height: 360
    4. Text {
    5. anchors.centerIn: parent
    6. text: "Hello World"
    7. }
    8. MouseArea {
    9. anchors.fill: parent
    10. onClicked: {
    11. Qt.quit();
    12. }
    13. }
    14.  
    15. }
    To copy to clipboard, switch view to plain text mode 

    If you want i can post all of my project here in a rar file??

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Using QDeclarativeView::Show()

    You are missing the following line:
    javascript Code:
    1. import QtQuick 1.0
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #7
    Join Date
    May 2011
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Symbian S60 Maemo/MeeGo

    Default Re: Using QDeclarativeView::Show()

    Hello Wysota

    thanks again for your reply, but my QML contains that, let me rephrase the problem again:

    1. following is my main.cpp where at first i am making an get request:
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication app(argc, argv);
    4.  
    5. NetworkRequest httpRequest;
    6. httpRequest.GetNewsResponse("http://iphone.blick.ch/");
    7.  
    8. QmlApplicationViewer viewer;
    9. viewer.setOrientation(QmlApplicationViewer::ScreenOrientationLockPortrait);
    10. viewer.setMainQmlFile(QLatin1String("qml/HybridApp/main.qml"));
    11. viewer.showExpanded();
    12.  
    13. return app.exec();
    14. }
    To copy to clipboard, switch view to plain text mode 

    Here main.qml contains a wait indicator and is waiting for the data from the server.

    2. Where NetworkRequest is a class derived from QObject and it simply helps in making an http get request from the method GetNewResponse.

    3. in NetworkRequest Class i have connect the finished(QNetworkReply*) signal of QNetworkAccessManager with my GotNetWorkReply(QNetworkReply*) slot of that class. Everything works fine here.

    4. Now when i get the reply from the network i write the following code:
    Qt Code:
    1. QFile file("qml/HybridApp/HomeScreen.qml");
    2. if(file.exists())
    3. {
    4. qDebug()<< "file exists";
    5. QDeclarativeView homeScreenView;
    6. homeScreenView.setSource(QUrl::fromLocalFile("qml/HybridApp/HomeScreen.qml"));
    7. homeScreenView.showFullScreen();
    8. }
    9. else
    10. {
    11. qDebug()<<"hell file doesnt exists";
    12. }
    To copy to clipboard, switch view to plain text mode 

    5. Here HomeScreen.qml contains :
    Qt Code:
    1. import QtQuick 1.0
    2.  
    3. Rectangle {
    4. width: 360
    5. height: 640
    6. color: "red"
    7. }
    To copy to clipboard, switch view to plain text mode 


    5. Now what i want is when i get the ansynchronous reply from the webserver i want to show this QML file, using some possible options, i am trying that using QDeclarativeView::Show(), but its not working the QML file doesnt comes up.

    Hope you now got my problem???

    Waiting for your reply.

  9. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Using QDeclarativeView::Show()

    Quote Originally Posted by proj_symbian View Post
    3. in NetworkRequest Class i have connect the finished(QNetworkReply*) signal of QNetworkAccessManager with my GotNetWorkReply(QNetworkReply*) slot of that class. Everything works fine here.
    Does the slot get called?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #9
    Join Date
    May 2011
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Symbian S60 Maemo/MeeGo

    Default Re: Using QDeclarativeView::Show()

    yes the slot gets called infact when i set break point my break point goes inside the file.exists() statement. over the QDeclarativeView::show method but the QML file never comes up.

  11. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Using QDeclarativeView::Show()

    Does the same qml file work when called with qmlviewer?

    By the way, you can pass a remote url to QDeclarativeView::setSource() and the file will be downloaded automatically if available.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #11
    Join Date
    May 2011
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Symbian S60 Maemo/MeeGo

    Default Re: Using QDeclarativeView::Show()

    yes it works separately in the QMLViewer and i have tried the other way too by placing that in a remote url, but nothing happens.

    I have attached the code here if you have time please have a look and let me know, its such a simple thing but its not happening. :-(

    Regards,
    Attached Files Attached Files

  13. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Using QDeclarativeView::Show()

    You are creating a new declarative view on the stack so it gets out of scope and is destroyed immediately.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  14. The following user says thank you to wysota for this useful post:

    proj_symbian (30th May 2011)

  15. #13
    Join Date
    May 2011
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Symbian S60 Maemo/MeeGo

    Default Re: Using QDeclarativeView::Show()

    oh yes yes that was the problem indeed thanks a lot wysota for your patience and help,

    i have one more doubt is this the correct approach i am doing or there is any better approach to update data on QML file?? I have gone through the docs but i was not able to understand.

    Regards,

  16. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Using QDeclarativeView::Show()

    I don't know what is best but I don't see a point in creating a new declarative view if you just want to change the script. You can call setSource() on the existing view.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  17. #15
    Join Date
    May 2011
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Symbian S60 Maemo/MeeGo

    Default Re: Using QDeclarativeView::Show()

    yes you are correct, but how can i get the reference of QApplicationViewer present in main.cpp to my NetworkManager class??

    I know this is a very basic question but i am not able to do that

  18. #16
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Using QDeclarativeView::Show()

    It doesn't have to be in the NM class. Emit a signal and catch it elsewhere where you have a pointer to the view at hand.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  19. #17
    Join Date
    May 2011
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Symbian S60 Maemo/MeeGo

    Default Re: Using QDeclarativeView::Show()

    apologies but its still not clear , i have a pointer of QApplicationViewer in main.cpp only, how can i get that on my NM class, are you telling i need to emit a signal from my main.cpp but i guess thats not possible.

    a simple code example for illustration will be greatful.

  20. #18
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Using QDeclarativeView::Show()

    Quote Originally Posted by proj_symbian View Post
    apologies but its still not clear , i have a pointer of QApplicationViewer in main.cpp only, how can i get that on my NM class, are you telling i need to emit a signal from my main.cpp but i guess thats not possible.
    So create another class to encapsulate what you already have or subclass QApplicationViewer and add appropriate slot to it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 2
    Last Post: 9th May 2011, 03:04
  2. Show Gif from url with QMovie
    By madlymad in forum Newbie
    Replies: 1
    Last Post: 12th November 2010, 16:56
  3. Replies: 3
    Last Post: 12th July 2010, 14:12
  4. How to not show widget
    By gQt in forum Qt Programming
    Replies: 9
    Last Post: 10th June 2010, 20:59
  5. Show in center
    By lisa in forum Qt Programming
    Replies: 3
    Last Post: 22nd November 2009, 12:42

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.