Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Casting a auto_ptr<QWidget> to QWidget

Casting a auto_ptr<QWidget> to QWidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 1.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sunil.nair
    wrote on last edited by
    #1

    Hi I am trying to cast a auto_ptr<QWidget> to a QWidget. I have tried multiple things : including

    std::auto_ptr<QWidget> nativeWidget;
    QWidget widget=static_cast<auto_ptr<QWidget> >(nativeWidget);

    It gives me an error that std::auto_ptr<QWidget> cannot be cast as a QWidget.
    How can I cast it?

    raven-worxR 2 Replies Last reply
    0
    • S sunil.nair

      Hi I am trying to cast a auto_ptr<QWidget> to a QWidget. I have tried multiple things : including

      std::auto_ptr<QWidget> nativeWidget;
      QWidget widget=static_cast<auto_ptr<QWidget> >(nativeWidget);

      It gives me an error that std::auto_ptr<QWidget> cannot be cast as a QWidget.
      How can I cast it?

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @sunil.nair
      Since QWidget derives from QObject, there are no assignment/copy operators available. You need to use only pointer types (unless you construct it on the stack)

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      2
      • S sunil.nair

        Hi I am trying to cast a auto_ptr<QWidget> to a QWidget. I have tried multiple things : including

        std::auto_ptr<QWidget> nativeWidget;
        QWidget widget=static_cast<auto_ptr<QWidget> >(nativeWidget);

        It gives me an error that std::auto_ptr<QWidget> cannot be cast as a QWidget.
        How can I cast it?

        raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by raven-worx
        #3

        @sunil.nair
        anyway, there is no need to do a cast in your case:

        QWidget* widget = nativeWidget.get(); // or use release(); read the docs to see what is more applicable for your usecase
        

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        0
        • B Offline
          B Offline
          bsomervi
          wrote on last edited by bsomervi
          #4

          If you have C++11 capabilities then you are better using std::unique_ptr<T>, std::auto_ptr<T> is deprecated. That too has std::unique_ptr<T>::get() to access the raw pointer and std::unique_ptr<T>::release() to take over ownership of the object pointed to.

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved