Discussion Board

Results 1 to 11 of 11
  1. #1
    Registered User henranto's Avatar
    Join Date
    Jun 2006
    Posts
    39
    Hi

    I'm having problem using QtMobility from multiple threads.

    Main-thread A starts and creates a QSystemDeviceInfo
    A creates thread B
    B then freeze when it tries to create QSystemNetworkInfo

    However if I just create and delete a QSystemNetworkInfo in thread A, thread B is working correctly. This worked until I wanted to use QNetworkSession, I can create an instance of this session but I don't get any signals from it, unless I remove the QSystemDeviceInfo access in main-thread.

    I think the problem could be the s60-implementation in QtMobility, as it uses static member of DeviceInfo which is used in both QSystemDeviceInfo and QSystemNetworkInfo but I'm not sure. I'm thinking of create a bug report for this but I wanted to check if anyone else have encountered this, or maybe if I'm doing something wrong.

    Thanks
    anton

  2. #2
    Nokia Developer Moderator divanov's Avatar
    Join Date
    Oct 2009
    Posts
    4,326
    It's hard to say anything definitive on the basis of so vague description. However, if there is a singleton data and multiple threads, you should be using mutexes.

  3. #3
    Registered User Sorcery-ltd's Avatar
    Join Date
    Dec 2006
    Posts
    2,280
    When you say your thread freezes, what do you mean - crashes, panics, blocks?

    Most likely you're running into the common problem for Symbian that most resource handles are not shared between threads by default. The easiest thing to do here is create a minimal app to reproduce this and raise a bug on Qt Mobility with the project attached. They'll either sort out the necessary handle sharing within Qt Mobility, or hopefully sort out the docs to say that multi-threaded access is not supported.

  4. #4
    Registered User henranto's Avatar
    Join Date
    Jun 2006
    Posts
    39
    My first thought it was hanging but more I just realized that it was the thread that crashed. I tested it on win32 and get some warnings when just creating QSystemNetworkInfo from other thread than main-thread:

    QObject: Cannot create children for a parent that is in a different thread.
    (Parent is WorkerThread(0x17a2310), parent's thread is QThread(0x15c7b50), current thread is WorkerThread(0x17a2310)

    Think I will build a test-app and report it.

    You say that it is a common problem in Symbian with resources, what is the best practice to go around such an issue?

    Thanks
    anton

  5. #5

  6. #6
    Nokia Developer Champion danhicksbyron's Avatar
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209
    Not a bug, I don't think. Objects are "owned" by threads. The message "QObject: Cannot create children for a parent that is in a different thread." is telling you that you're directly or indirectly creating an object in one thread and specifying a parent in a different thread. This is a no-no, since the parent can't safely delete the child.

  7. #7
    Registered User henranto's Avatar
    Join Date
    Jun 2006
    Posts
    39
    Yes I agree about the parent and child must be in same thread but isn't it strange that this warning is given even if I only create it in the worker-thread? Seems like the resource-objects are created by the main-thread at startup (win32)?

    And still it is unclear to me how to solve the issue of using mobility objects in another threads, as the different classes (in my case QSystemNetworkInfo and QSystemDeviceInfo) are using same static members in the underlying implementation. If the solution is to only use these objects from same thread it should at least be documented somewhere. Or is it something I have missed?

  8. #8
    Nokia Developer Champion danhicksbyron's Avatar
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209
    How did you construct the QSystemNetworkInfo?

  9. #9
    Registered User henranto's Avatar
    Join Date
    Jun 2006
    Posts
    39
    Code:
    QSystemNetworkInfo *netInfo = new QSystemNetworkInfo(this);
    Even without "this" will not work. Complete code example is included in bug report if you are interested.

  10. #10
    Nokia Developer Champion danhicksbyron's Avatar
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209
    Well, it certainly will not work with "this", if the "this" object was constructed in another thread.

  11. #11
    Nokia Developer Expert lpotter's Avatar
    Join Date
    Jun 2008
    Location
    Brisbane, Australia
    Posts
    18
    I have commented on this in the bug report.
    http://bugreports.qt.nokia.com/browse/QTMOBILITY-1058
    Code Monkey, QtMobility, Nokia

Similar Threads

  1. CPbkContactEngine in multiple threads
    By budugu in forum Symbian Tools & SDKs
    Replies: 6
    Last Post: 2010-04-14, 13:00
  2. Multiple threads problem
    By kunlamp in forum Symbian C++
    Replies: 4
    Last Post: 2009-11-04, 05:34
  3. multiple threads access to devsound
    By pavankrishnamurthy in forum Symbian Media (Closed)
    Replies: 3
    Last Post: 2006-10-18, 10:18
  4. multiple threads:how MANY???
    By etamburini in forum Mobile Java General
    Replies: 4
    Last Post: 2003-12-04, 12:14
  5. STDLIB and multiple threads
    By lab1348 in forum Symbian C++
    Replies: 0
    Last Post: 2003-07-24, 16:08

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved