Results 1 to 6 of 6

Thread: Why do some QWidgets create own threads?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    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.

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

    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 


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

    Default Re: Why do some QWidgets create own threads?

    Am I the only one where QLineEdit creates threads?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    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?

  5. #5
    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 19:13.
    Q7Goodies - The sweetest way to add Windows 7 features to your Qt application

Similar Threads

  1. Replies: 8
    Last Post: 27th March 2013, 12: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
  •  
Qt is a trademark of The Qt Company.