Results 1 to 6 of 6

Thread: Why do some QWidgets create own threads?

  1. #1
    Join Date
    Jul 2008
    Posts
    66
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Why do some QWidgets create own threads?

    Hi,

    I am working on a multi-threading program, which has the ability to create dynamically pages for the Tab-Widget.
    These pages for the tab-widget are made of a self made page-template class.

    In that template I have the whole widgets I need to create that page.
    All of them are created on the Heap.

    My theory is:
    my_programs_core (5 Threads) + main_gui( 1 Thread)

    But it is:
    my theory(6 Threads) + QLineEdit of mainGUI(2 Threads) + QFileDialog for save and load (2 Threads)..

    My question is:
    Why do a QLineEdit located on my main-page (not on the pages for the Tab-Widget)
    creates 2 Threads?

    And in my template-class there are two QFileDialog instances for each page. (Load file / save file)
    It means every time I create a new page with my template class I will get 2 Threads without a reason.

    Can someone explain me that?

  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: Why do some QWidgets create own threads?

    QFileDialog might be using a separate thread for populating QFileSystemModel. QLineEdit shouldn't be using separate threads unless you are using a completer with QFileSystemModel.

  3. #3
    Join Date
    Jul 2008
    Posts
    66
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Why do some QWidgets create own threads?

    Thanks,

    you are right
    Qt Code:
    1. QFileDialog *aaa = new QFileDialog(this);
    2.  
    3. somewhere in the code:
    4. model = new QFileSystemModel(q);
    To copy to clipboard, switch view to plain text mode 

    But QLineEdit creates 2 Threads in my simple case.

    Qt Code:
    1. QLineEdit *bbb = new QLineEdit(this);
    To copy to clipboard, switch view to plain text mode 

    Somewhere in the code in its init

    Qt Code:
    1. q->setAcceptDrops(true); //here it creates 2 threads
    To copy to clipboard, switch view to plain text mode 


  4. #4
    Join Date
    Jul 2008
    Posts
    66
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Why do some QWidgets create own threads?

    Am I the only one where QLineEdit creates threads?

  5. #5
    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: Why do some QWidgets create own threads?

    QLineEdit is not using any threads, at least not by itself. Why did you think it was using threads?

  6. #6
    Join Date
    May 2010
    Location
    Czestochowa, Poland
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Why do some QWidgets create own threads?

    donglebob is right. Instantiating QLineEdit creates threads of its own. On my system (Windows 7, Qt 4.6.2) it creates 4 threads! Actually, the threads are created inside QWidget::setAcceptDrops(), because QLineEdit calls this method inside the constructor. After a bit more debugging I've found out that the threads are created by a WinAPI function CoLockObjectExternal

    Edit: I've found a way to prevent this behavior. One must call
    Qt Code:
    1. QLineEdit::setAcceptDrops(false);
    To copy to clipboard, switch view to plain text mode 
    before the widget is shown.
    Last edited by Strix Code; 6th July 2010 at 18:13.
    Q7Goodies - The sweetest way to add Windows 7 features to your Qt application

Similar Threads

  1. Replies: 8
    Last Post: 27th March 2013, 11:51

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.