Results 1 to 5 of 5

Thread: How to access TextEditBox of one class in another class in another file

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: How to access TextEditBox of one class in another class in another file

    You cannot access GUI objects (QTextEdit) from another thread (QThread::run()).

    Instead send signal from the Serial_Port object and receive it from a slot of CVmThread.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to access TextEditBox of one class in another class in another file

    Quote Originally Posted by Santosh Reddy View Post
    You cannot access GUI objects (QTextEdit) from another thread (QThread::run()).

    Instead send signal from the Serial_Port object and receive it from a slot of CVmThread.
    Or the other way around, depending on which of the two classes produces the data and which one consumes it.

    So instead of calling setPlainText() on the text edit you would emit a signal carrying a QString and connect that to the setPlainText() slot or to a slot that in turn calls setPlainText()

    Cheers,
    _

    P.S.: even if it weren't for the threading issue, accessing some other classes internal members is almost always a bad idea. Methods in Serial_Port that then all methods if Serial_Port internals is way cleaner

Similar Threads

  1. How to access the UI from another class ?
    By fitzy in forum Qt Programming
    Replies: 22
    Last Post: 20th July 2016, 14:21
  2. Access from other class
    By champ in forum Newbie
    Replies: 2
    Last Post: 12th June 2010, 16:04
  3. Replies: 4
    Last Post: 29th May 2010, 12:56
  4. Replies: 3
    Last Post: 27th December 2008, 19:34
  5. Replies: 5
    Last Post: 14th July 2006, 22:42

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.