×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    63

    [moved] Use Symbian C++ code to open default browser from a Qt app

    Hello,

    I'm trying to open an URL from a Qt app in the browser set as the default browser in the Symbian settings. Therefore I found this one: http://www.developer.nokia.com/Commu...ymbian_C%2B%2B

    It's mainly now only about Symbian:penUrlInDefaultBrowser(QString url); and Symbian::LaunchBrowserL(const TDesC& aUrl, TUid& _id);. I know that in the first one url isn't used yet. I'm able to compile and build this code with the following libs included:
    Code:
    LIBS += -lcone \ #openDefaultBrowser
    -leikcore \ #openDefaultBrowser
    -lavkon \
    -lws32\
    -lapgrfx\ #openDefaultBrowser
    -leikcoctl\
    -leiksrv\
    -lProfileEngine \
    -letel3rdparty\
    -lQtMessaging \
    -letel\
    -lfeatdiscovery\
    -lc32\
    -laknicon\
    -laknskins\
    -laknnotify\
    -lapmime #openDefaultBrowser
    }
    But if I try to use this code on the device nothing happens. As the device is not connected to QtCreator (never figured that out and it'll be far complicated cause QtCreator is running in VMware) and the Qt Simulator is not able to run Symbian code I'm not able to give any debug messages or so. But I hope that you can help me anyway, maybe there is somewhere something I missed or don't see as a bug, cause I'm not good in Symbian C++...

    Both files:
    http://dl.dropbox.com/u/95990477/Qt/symbian.h
    http://dl.dropbox.com/u/95990477/Qt/symbian.cpp

    Best Regards,
    schumi1331

  2. #2
    Nokia Developer Champion
    Join Date
    Jun 2008
    Location
    Noida,India
    Posts
    4,076

    Re: Use Symbian C++ code to open default browser from a Qt app

    Is it possible for you to make log files in your code & check till what point the code executes(make the log directory somewhere in C:\\data\\ for e.g).

    Note: Please make sure that the browser is not already launched when you try to do that from your app ( trying to launch the browser from code when its already running would do nothing)

  3. #3
    Nokia Developer Moderator
    Join Date
    Sep 2004
    Location
    Tampere, Finland
    Posts
    11,359

    Re: Use Symbian C++ code to open default browser from a Qt app

    The browser launching is handled correctly (at least for the native browser case) when the browser is running, i.e. task.Exists() in http://www.developer.nokia.com/Commu...in_3rd_edition but the application would require the SwEvent capability in that case.

    schumi1331, if the code compiles and runs without crashing, check indeed if you have the target browser running and if so, whether you have the SeEvent capability. Also, it might be relevant to know which browser you are targeting, but at least with the build-in one you should always see the solution working.
    -- Lucian

    If you are not yet a DVLUP member it is time to correct that mistake :) Click here to join: http://www.dvlup.com/lucian/Invite

  4. #4
    Registered User
    Join Date
    Nov 2009
    Posts
    63

    Re: Use Symbian C++ code to open default browser from a Qt app

    Hm, thanks for your replies. I modified now my code to have a log function in it and the error I get is:
    TypeError: Result of expression 'symbian.openUrlInDefaultBrowser' [undefined] is not a function.
    I checked the symbian.h to have Q_OBJECT at the top and that's how I'm adding it in main.cpp:
    Code:
    #include "symbian.h"
    ...
    Q_DECL_EXPORT int main(int argc, char *argv[])
    {
        QScopedPointer<QApplication> app(createApplication(argc, argv));
        ...
        Symbian symbian;
        QmlApplicationViewer viewer;
    
        viewer.rootContext()->setContextProperty("symbian", &symbian);
        ...
        viewer.showExpanded();   
    
        return app->exec();
    And here's how I'm calling it from QML:
    Code:
    ToolButton {
                id: rightButton
                flat: true
                visible: driverModel.get(currentIndex).twitter == "" ? false : true
                enabled: driverModel.get(currentIndex).twitter == "" ? false : true
                iconSource: "images/qtg_toolbar_twitter.svg"
    
                onClicked: {
                    symbian.openUrlInDefaultBrowser("http://twitter.com/"+driverModel.get(currentIndex).twitter)
                }
            }
    "driverModel.get(currentIndex).twitter" is a string and is returned correctly, so visible and enabled work how they should work. I have absolutely no idea what's wrong here...

  5. #5
    Nokia Developer Champion
    Join Date
    Jun 2008
    Location
    Noida,India
    Posts
    4,076

    Re: Use Symbian C++ code to open default browser from a Qt app

    You said in #1 that you were able to compile the code successfully & the error you have stated now does not seems to be that due to the log function(though you have not posted the function here).

    Was this symbian.openUrlInDefaultBrowser() compiling earlier successfully?

  6. #6
    Registered User
    Join Date
    Nov 2009
    Posts
    63

    Re: Use Symbian C++ code to open default browser from a Qt app

    thanks for moving the thread

    @vineet.jain: I posted the function openUrlInDefaultBrowser in the first post in the linked cpp/h file (symbian.cpp & symbian.h at the bottom of #1). Everything was compiled successfully.

  7. #7
    Nokia Developer Champion
    Join Date
    Jun 2008
    Location
    Noida,India
    Posts
    4,076

    Re: Use Symbian C++ code to open default browser from a Qt app

    Can you please paste the content of cpp & .h here, enclosed inside code tag separately. With html view of these files, its not formatted.

    Apart from that i wanted to know the same, what did you changed with regards to the calling of this function from qml which has now started to throw this compilation error.

  8. #8
    Registered User
    Join Date
    Nov 2009
    Posts
    63

    Re: Use Symbian C++ code to open default browser from a Qt app

    The TypeError I'm getting from QML is stored in the log file you told me to implement. It's not an error when compiling but it appears when I press the ToolButton.

    Code:
    #ifndef SYMBIAN_H
    #define SYMBIAN_H
    
    #include <QObject>
    
    /*
    Includes of Symbian libraries. If you are building for multiple OSes, use
    #ifdef Q_OS_SYMBIAN
    ...
    #endif
    
    DON'T FORGET TO ADD LIBS TO THE PRO FILE OF YOUR PROJECT
    */
    //General
    #include <eikenv.h>
    //sendNotification
    #include <eikappui.h>
    #include <aknenv.h>
    #include <aknappui.h>
    #include <e32base.h>
    #include <w32std.h>
    #include <apgwgnam.h>
    #include <coedef.h>
    #include <coecntrl.h> // CCoeControl
    #include <coemain.h>
    #include <iconv.h>
    #include <coeaui.h>
    #include <eikapp.h>
    #include <coemain.h>
    #include <eikdef.h>
    #include <apgtask.h>
    #include <aknglobalnote.h>
    //openUrlInDefaultBrowser
    #include <apgcli.h>
    #include <apgtask.h>
    
    class Symbian : public QObject
    {
        Q_OBJECT
    public:
        explicit Symbian(QObject *parent = 0);
    
        Q_INVOKABLE void openUrlInDefaultBrowser(QString url);
    
        void sendNotification(QString notetext);
    
        void LaunchBrowserL(const TDesC& aUrl, TUid& _id);
    };
    
    #endif // SYMBIAN_H
    Code:
    #include "symbian.h"
    
    Symbian::Symbian(QObject *parent) :
        QObject(parent)
    {
    }
    
    /*
    Following code is used to open a URL from a Qt app in the default browser that can
    be selected in the OS' settings (Settings > Program settings > Default programs >
    Internet). By default when using Qt.openUrlExternally(), the Symbian Web Browser
    is opened independent if the set browser is Opera, etc.
    Maybe this will be fixed by Nokia sometimes but hard to believe (and then it
    wouldn't work in older OS versions I think).
    
    Further informations:
    http://www.developer.nokia.com/Community/Wiki/Launch_default_web_browser_using_Symbian_C%2B%2B
    http://www.developer.nokia.com/Community/Wiki/How_to_Launch_Browser_in_3rd_edition
    */
    void Symbian::openUrlInDefaultBrowser(QString url) {
        RApaLsSession lsSession;
        // create a session with apparc server.
        User::LeaveIfError(lsSession.Connect());
        CleanupClosePushL(lsSession);
        TDataType mimeDatatype(_L8("application/x-web-browse"));
        TUid handlerUID;
        // get the default application uid for application/x-web-browse
        lsSession.AppForDataType(mimeDatatype,handlerUID);
        // there may not be a mime-type handler defined, especially on S60 3.x
        // in such case we default to the built-in browser
        if (handlerUID.iUid == 0) {
            const TInt KWmlBrowserUid = 0x10008D39;
            TUid id( TUid::Uid( KWmlBrowserUid ) );
            handlerUID = id;
        }
        // Finally launch default browser
        _LIT(KBrowserUrl,"http://www.google.com");
        LaunchBrowserL(KBrowserUrl, handlerUID);
        // Cleanup
        CleanupStack::PopAndDestroy(&lsSession);
    }
    // ----------------------------------------------------
    // CBrowserAppUi::LaunchBrowserL(const TDesC& aUrl, TUid& aUid)
    // Used for launching the default browser with provided url.
    // (modified, see second link)
    // ----------------------------------------------------
    //
    void Symbian::LaunchBrowserL(const TDesC& aUrl, TUid& _id)
    {
        TApaTaskList taskList( CEikonEnv::Static()->WsSession() );
        TApaTask task = taskList.FindApp( _id );
        if ( task.Exists() )
        {
            HBufC8* param = HBufC8::NewLC( aUrl.Length() + 2);
                    //"4 " is to Start/Continue the browser specifying a URL
            param->Des().Append(_L("4 "));
            param->Des().Append(aUrl);
            task.SendMessage( TUid::Uid( 0 ), *param ); // Uid is not used
            CleanupStack::PopAndDestroy(param);
        }
        else
        {
            HBufC16* param = HBufC16::NewLC( aUrl.Length() + 2);
                    //"4 " is to Start/Continue the browser specifying a URL
            param->Des().Append(_L("4 "));
            param->Des().Append(aUrl);
            RApaLsSession appArcSession;
                    // connect to AppArc server
            User::LeaveIfError(appArcSession.Connect());
            TThreadId id;
            appArcSession.StartDocument( *param, _id, id );
            appArcSession.Close();
            CleanupStack::PopAndDestroy(param);
        }
    }
    
    /*
    Following code is used to send a global notification in Symbian OS from a Qt app.
    The notification will be centered on the screen and overlapping and breaking other
    apps usages for the moment of displaying.
    Change "EAknGlobalInformationNote" to show a warning, error, or prompt.
    
    Further informations:
    From (Symbian C++ Notifiers API):
    http://www.developer.nokia.com/Community/Discussion/showthread.php?222947-How-to-add-an-icon-to-a-native-notifier/page2&highlight=caknglobalnote+qt
    http://www.developer.nokia.com/document/Cpp_Developers_Library/GUID-759FBC7F-5384-4487-8457-A8D4B76F6AA6/html/Notifiers_API4.html
    
    Info pop up:
    http://library.developer.nokia.com/index.jsp?topic=/Nokia_Belle_Developers_Library/GUID-2BD07F78-4275-4274-B20C-8AB14D3C3D20.html
    */
    void Symbian::sendNotification(QString notetext) {
        TInt NoteId = -1;
        CAknGlobalNote* dialog = CAknGlobalNote::NewLC();
        TPtrC16 textPtr(reinterpret_cast<const TUint16*>(notetext.utf16()));
        NoteId = dialog->ShowNoteL(EAknGlobalInformationNote,textPtr);
        //User::After(2000000);
        //dialog->CancelNoteL(NoteId);
    
        CleanupStack::PopAndDestroy(dialog);
    
        /*CAknGlobalNote* note = CAknGlobalNote::NewLC();
        _LIT(KInfoText, "Information");
        note->ShowNoteL(EAknGlobalInformationNote, KInfoText);
        CleanupStack::PopAndDestroy(note);*/
    }

  9. #9
    Nokia Developer Champion
    Join Date
    Jun 2008
    Location
    Noida,India
    Posts
    4,076

    Re: Use Symbian C++ code to open default browser from a Qt app

    Ahh ok my bad, it must be an runtime error. Well all the things looks really fine actually, the Q_OBJECT macro in header, the Q_INVOKABLE declaration etc.(absence of either might have resulted in the error your are getting). You can try calling the function from somewhere else then the ToolButton , just for test purpose & see if error is still there.

  10. #10
    Registered User
    Join Date
    Nov 2009
    Posts
    63

    Re: Use Symbian C++ code to open default browser from a Qt app

    ah, I found the reason for the QML bug: It seems that there is a problem when I name the Symbian object "symbian":
    Code:
    viewer.rootContext()->setContextProperty("symbian", &symbian);
    if I do it like this (changes marked bold) it works (of course with using symbianfcts.openUrlInDefaultBrowser() in QML):
    Code:
    viewer.rootContext()->setContextProperty("symbianfcts", &symbian);

    so the thread may be moved to Symbian C++ back :
    First one:
    Note: Please make sure that the browser is not already launched when you try to do that from your app ( trying to launch the browser from code when its already running would do nothing)
    I tested this now with Opera Mobile and default Symbian Web Browser on Belle FP2, 113.010.1506 on 808 PV. When I set Opera as the default browser and open if before or while my app is open and open a tab in it, the code I use work. So a second tab with the URL I pass from my app is opened and everything works fine.
    When having the Symbian Web Browser as default nothing happens when the browser is already opened (as you already wrote). Is there any workaround or how to catch this (cause users will surely report this later as a bug ^^)? (remember: I have no idea about Symbian C++)

    Second one:
    Code:
    _LIT(KBrowserUrl,"http://www.google.com/");
    This works fine if I set the URL static as shown a line above. But how do I get a string (or sth else, I don't know?) that fits into this when I get it as a QString. Means if I change this to
    Code:
    _LIT(KBrowserUrl,url);
    where url is a QString passed from QML it doesn't work, that's the result from compiler:
    Code:
       symbian.cpp: In member function 'void Symbian::openUrlInDefaultBrowser(QString)':
       symbian.cpp:40: error: 'Lurl' was not declared in this scope
       symbian.cpp:40: error: template argument 1 is invalid
       symbian.cpp:40: error: invalid type in declaration before '=' token
       symbian.cpp:40: error: scalar object 'KBrowserUrl' requires one element in initializer
    Hope it's understandable what I want to say

    Best Regards,
    schumi1331

  11. #11
    Registered User
    Join Date
    Nov 2009
    Posts
    63

    Re: Use Symbian C++ code to open default browser from a Qt app

    Really sorry for "bumping" this topic but is anyone able to help?

  12. #12
    Nokia Developer Champion
    Join Date
    Jun 2008
    Location
    Noida,India
    Posts
    4,076

    Re: Use Symbian C++ code to open default browser from a Qt app

    You might want to explain the issue you are facing, probably if that is same then its already resolved in #10.

  13. #13
    Registered User
    Join Date
    Nov 2009
    Posts
    63

    Re: Use Symbian C++ code to open default browser from a Qt app

    I explained both issues/problems I still have in #10.

    Summarizing shortly (see #10 for full explanation):
    1. When I use the Symbian C++ code to open web page and have Symbian Web Browser set as default and the browser is already opened, the app is not passing the URL or opening the page (as you already described). When I use the the Symbian C++ code and have Opera Mobile set as default and the browser is already opened, it passes the URL and opens a new tab in Opera. How am I able to catch the first case to give an info for the user so that he doesn't think this is a bug? So how can I receive any info that it couldn't open the browser and handle it in my app?

    2. How do I pass a QString to the Symbian C++ functions? Here I especially mean the line "_LIT(KBrowserUrl,url);", where url is a QString passed from QML (or somewhere else). This doesn't work (see compiler message in #10) and I don't know how to convert the QString that it will work with Symbian C++. As I said I have no Symbian C++ knowledge and try to get this running with your help

  14. #14
    Nokia Developer Champion
    Join Date
    Jun 2008
    Location
    Noida,India
    Posts
    4,076

    Re: Use Symbian C++ code to open default browser from a Qt app

    Ahh... I am sorry for misreading your name. I thought some else has hijacked this thread & asking then, I did not bothered to scroll down & see.

    For issue #2, have you seen this : http://www.developer.nokia.com/Commu...Buf_to_QString

  15. #15
    Registered User
    Join Date
    Nov 2009
    Posts
    63

    Re: Use Symbian C++ code to open default browser from a Qt app

    aha, finally it's all working

    Using the code in your link gave me the error "LtextPtr was not declared in this scope", looks like it's the same as here: http://www.developer.nokia.com/Commu...l=1#post783206

    But I found this on the web: http://qml-tieba-client.googlecode.c...c5/utility.cpp so the correct and working openUrlInDefaultBrowser looks like this:
    Code:
    void Symbian::openUrlInDefaultBrowser(QString url) {
        // Convert QString to use it within Symbian C++
        TPtrC myUrl (reinterpret_cast<const TText*>(url.constData()),url.length());
    
        RApaLsSession lsSession;
        // create a session with apparc server.
        User::LeaveIfError(lsSession.Connect());
        CleanupClosePushL(lsSession);
        TDataType mimeDatatype(_L8("application/x-web-browse"));
        TUid handlerUID;
        // get the default application uid for application/x-web-browse
        lsSession.AppForDataType(mimeDatatype,handlerUID);
        // there may not be a mime-type handler defined, especially on S60 3.x
        // in such case we default to the built-in browser
        if (handlerUID.iUid == 0) {
            const TInt KWmlBrowserUid = 0x10008D39;
            TUid id( TUid::Uid( KWmlBrowserUid ) );
            handlerUID = id;
        }
        // Finally launch default browser
        LaunchBrowserL(myUrl, handlerUID);
        // Cleanup
        CleanupStack::PopAndDestroy(&lsSession);
    }
    And to be able to open a new tab when Symbian Web Browser is already running, you need the SwEvent capability, found here: https://bugreports.qt-project.org/br...mment-tabpanel

    Can you tell me if SwEvent capability is covered by Nokia Store Signing? Couldn't find anything about it...

Similar Threads

  1. Open default browser from qml
    By CristianL in forum [Archived] Qt Quick
    Replies: 3
    Last Post: 2011-08-12, 17:12
  2. How to open the default browser with URL path
    By ashraf fawzy in forum Symbian Networking & Messaging (Closed)
    Replies: 1
    Last Post: 2011-04-16, 10:48
  3. How to open a url in default browser?
    By arnab321 in forum Symbian
    Replies: 1
    Last Post: 2011-03-15, 07:23
  4. [moved] Open source a simple Symbian C++ code with use Google static map API
    By zhang_guoqing in forum News and Announcements
    Replies: 8
    Last Post: 2010-09-16, 20:04
  5. open local file with default browser?
    By brah in forum Browsing and Mark-ups
    Replies: 3
    Last Post: 2005-06-24, 13:37

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×