×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    28

    Post Programming errors in code example Qts60aoexample

    Hi, I've noticed some errors/concerns in said example.

    My Comments, preceded by ***


    File: AOWRAPPER_S60_P.H
    class AOWrapperPrivate: public QObject,
    public CActive ***


    I can’t see a good reason to derive from both QObject and CActive. This form of multiple inheritances can lead to some serious problems, and while I don’t think it's an issue here, it almost implies that the bridge class between Qt and Symbian needs to inherit from both CBase and QObject.

    A few examples where this may break are:
    • CActive is-a CBase class and must always live on the heap (where as QObject can be stack or heap based).
    • CBase relies on the memory being zeroed before the constructor is called, it achieves this by overloading the new operator CBase:perator new() . This could throw up some subtle problems, but also could lead to compile errors in future if say QObject derived class ever defined a new operator.

    Let’s not encourage MI unless it’s really a benefit.


    File: telephonywidget.cpp

    // =========== PRIVATE CLASS MEMBER FUNCTIONS ===============
    //
    // ---------------------------------------------------------
    // AOWrapperPrivate::AOWrapperPrivate()
    // Constructor
    // ---------------------------------------------------------
    //
    AOWrapperPrivate::AOWrapperPrivate(AOWrapper *wrapper)
    : CActive(EPriorityStandard), q_ptr(wrapper),
    iTelephony(NULL), iPhoneIdV1Pckg(iPhoneIdV1)
    {
    TRAP_IGNORE(iTelephony = CTelephony::NewL());
    ***Error code swallowed. This could be “KErrInUse” or any other Symbian code, not KErrNoMemory;



    // Added to active scheduler only once
    if (iTelephony) {
    CActiveScheduler::Add(this);
    }
    }


    .

    // ---------------------------------------------------------
    // AOWrapperPrivate::RequestManufacturer()
    // Requests phone id.
    // ---------------------------------------------------------
    //
    int AOWrapperPrivate::RequestManufacturer()
    {
    int error = 0;
    if (iTelephony) {
    RequestPhoneId();
    } else {
    error = KErrNoMemory; *** This should at least be the error returned from CTelephony::NewL() in the constructor. Cache it?
    }
    return error;
    }

    // ---------------------------------------------------------
    // AOWrapperPrivate::RequestPhoneId()
    // Requests phone id information of the mobile device
    // ---------------------------------------------------------
    //
    void AOWrapperPrivate::RequestPhoneId()
    {
    ASSERT(!IsActive());
    iTelephony->GetPhoneId(iStatus, iPhoneIdV1Pckg); *** If constructor failed to allocate CTelephony, then this line would cause an access violation (dereferencing null).
    SetActive();
    }

  2. #2
    Registered User
    Join Date
    Dec 2006
    Posts
    2,280

    Re: Programming errors in code example Qts60aoexample

    TwmD is spot on here - this example should be updated before too many people start learning bad habits!

    Mark

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    7

    Re: Programming errors in code example Qts60aoexample

    Hi,

    Thanks for pointing that out. We've fixed it in the library now and it will be in the next release.

    Gary

Similar Threads

  1. Replies: 3
    Last Post: 2008-11-06, 16:19
  2. Replies: 2
    Last Post: 2008-04-07, 12:44
  3. Replies: 5
    Last Post: 2003-10-30, 14:44

Posting Permissions

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