PDA

View Full Version : VS to Qt



Teaser
28th June 2009, 00:10
I'm starting to play with Qt Creator having spent much time with Visual Studio.

My questions is simply: if I create a widget on a QMainApplication window can I access it directly in the code file by its name or must I use centralWidget->findChild() ?

It's a simple question but it's rather annoying me since I can see my MainWindow class inherits from Ui_MainWindow which has the widgets i've added to my window as public, yet I can't get to them directly.

Thanks

wysota
28th June 2009, 00:35
My questions is simply: if I create a widget on a QMainApplication window

There is no such thing as QMainApplication. You either mean QApplication or QMainWindow, right?


can I access it directly in the code file by its name or must I use centralWidget->findChild() ?
You can call it by its variable name.


It's a simple question but it's rather annoying me since I can see my MainWindow class inherits from Ui_MainWindow which has the widgets i've added to my window as public, yet I can't get to them directly.

Take a look at the code Creator generated for you. The ui component is either privately inherited by the widget or is its private component. In either case you should create accessor methods for the variables if you need to access them outside the class. Note that this is nothing Creator or Qt specific, but rather a proper object oriented approach. If you want to break it, just move the ui component to the public scope in the subclass.

Teaser
28th June 2009, 12:39
There is no such thing as QMainApplication. You either mean QApplication or QMainWindow, right?

Yes I meant QMainWindow.

I've came back to Qt Creator today and it is working as I expected (i.e. I can access widgets by their objectName from the code), so I don't know what was happening yesterday, but a shutdown/restart has poked things into action.

wysota
28th June 2009, 14:54
Yes I meant QMainWindow.

I've came back to Qt Creator today and it is working as I expected (i.e. I can access widgets by their objectName from the code), so I don't know what was happening yesterday, but a shutdown/restart has poked things into action.

You have to build the project for the ui completion to be available, if that was your problem.

Teaser
28th June 2009, 18:18
The project was built. I recently had the problem again so I did a clean then build and it was Ok. Not sure what the issue is - if it was that big a deal many others would have the problem.

(I'm on Vista 64bit, Qt Creator v1.1.0).

wysota
28th June 2009, 19:40
But what was happening? The project wasn't building or the code completion didn't work?