Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8196655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:33:19+00:00 2026-06-07T05:33:19+00:00

I have an array of my custom made buttons: Button buttons[5] Now I want

  • 0

I have an array of my custom made buttons:

Button buttons[5]

Now I want to swap two elements of this array, for example buttons[1] and buttons[2]. How do I do this? Just stating the following, doesnt work:

Button help = buttons[1];
buttons[1] = buttons[2];
buttons[2] = help;

Can anybody help me with this?

I have solved using a pointer array:

Button *pntArray[5];
Button *help;
pntArray[0]=&buttons[0];
pntArray[1]=&buttons[1];

help=pntArray[0];
pntArray[0]=pntArray[1];
pntArray[1]=help;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T05:33:20+00:00Added an answer on June 7, 2026 at 5:33 am

    QObject base class does not allow the assignment operator or the copy constructor. Unless you have manually created these (which is usually unwise), declare your instances on the heap and use pointers in the array instead.

    //  Instantiate the buttons however you like, if you were just creating them
    //  on the stack before, a default initialisation should suffice.  Though
    //  normally in Qt you would at least pass the 'owning' widget as the parent
    //  so you don't need to worry about deleting the buttons.
    QVector<Button*> buttons(5);
    for ( Button* button : buttons ) {  // C++11 only!
        button = new Button();
    }
    
    //  Then whenever you need to swap two entries:
    std::swap( buttons[1], buttons[2] );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array of custom objects. MyCustomArr[]. I want to convert this to
I have this very simple custom component, made out of two Labels : _left
I have a listview connected to a custom array adapter. This list shows information
I have a form and two custom UserControl that I made myself. one control
I have a PreferenceScreen made with a custom ListPreference and a CheckBoxPreference. This is
I have an array of custom class Student objects. CourseStudent and ResearchStudent both inherit
I have a custom array $myresults = @() $w3svcID = $result.ReturnValue -replace IISWebServer=, $w3svcID
I have an array (items) of custom class objects (catalogItem) each catalogItem has various
Possible Duplicate: mysql custom sort I have an array of IDs: $ids = array(5,
I have a custom object that I was adding to an array via a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.