Results 1 to 6 of 6

Thread: VS to Qt

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default VS to Qt

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: VS to Qt

    Quote Originally Posted by Teaser View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jun 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: VS to Qt

    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: VS to Qt

    Quote Originally Posted by Teaser View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jun 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: VS to Qt

    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).

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: VS to Qt

    But what was happening? The project wasn't building or the code completion didn't work?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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.