简体   繁体   中英

Accessing Textbox in MainWindow from another widget

I created a Qt5 UI-Application in QtCreator. It consists of a MainWindow with a PlainTextEdit and a custom widget called "Canvas" that is used for drawing stuff. Now, the PlainTextEdit is set to read-only and should be used as a log window for some status messages that might occur in the canvas widget. For this I created a "log" method in MainWindow that just appends some text to the PlainTextEdit.

However, I simply cannot find a way to access the textfield from within the canvas widget. I tried to get the parent widget of Canvas but failed somehow. I tried turning the MainWindow class into a singleton and get the instance of it, but that does not seem to work either.

So any tips on how you would go about creating a log window, that is usable globally from all widgets?

仅将信号添加到自定义窗口小部件并将其连接到PlainTextEdit插槽会更容易吗?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM