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 7956083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:53:22+00:00 2026-06-04T03:53:22+00:00

Given the following code: QList<Vertex*> _vertices; //this gets filled //at some other point i

  • 0

Given the following code:

QList<Vertex*> _vertices; //this gets filled

//at some other point i want to check if there's already
//a vertex with the same payload inside the list
Vertex* v = new Vertex(payload);
int result = _vertices.indexOf(v);
if (result == -1){
    //add the vertex to the list
} else {
    //discard v and return pointer to match
}

//overloaded Vertex::operator==
bool Vertex::operator==(Vertex* other){
    //i return true if my payload and the others
    //payload are the same
}

As far as I can see indexOf() never ends up calling my operator==. I assume this is because of QList encapsulating a pointer type and indexOf() comparing the pointers. Is there a way of keeping ponters in the QList and still using my own operator==()?

Like Vertex*::operator==(Vertex* other)

Related Questions: removing in pointer type Qlists | not working because of pointer type

Edit: Intention.

Two vertices are considered equal iff. identifiers carried by their payload are equal.

Vertex is part of a Graph class. I want clients of that class to be able to call Graph::addEdge(Payload,Payload) to populate the graph. Graph objects then take care of wrapping up Payloads in Vertex objects and building Edges. Hence Graph needs to check if a Vertex encapsulating a given payload doesn’t already exist. Using QList seemed like the “simplest thing that might work” at the time of writing the code.

  • 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-04T03:53:24+00:00Added an answer on June 4, 2026 at 3:53 am

    Is there a way of keeping ponters in the QList and still using my own
    operator==()?

    No, you would need QList to dereference the pointer first, which it doesn’t. You would have to subclass QList in order to do that. But as indexOf() just iterates through and compares using operator==() there’s nothing stopping you doing the same thing manually.

    However, all of this looks like a code smell. Trying to find something in an unordered/non-hashed container is in linear time – very slow compared to QMap/QHash. Please edit your question describing why you want to do this, and what data Vertex contains, and we’ll see if the community can up with better performing mechanism.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following code, is there a way I can call class A's version
Given the following code, How would you refactor this so that the method search_word
Given the following code snippets, is there any appreciable difference? public boolean foo(int input)
Given the following code. Is there any potential for the first DrawString method to
Given the following code <div class=container> <p>Some Text</p> <p><img src=image.jpg><p> <p>More Text</p> </div> CSS
Given the following code, I try to implement the public static Point operator +(int
This question is probably stupid or paranoidal, but anyway :-). Given following code: DWORD
Given the following code: value = time.mktime(datetime.fromtimestamp(timestamp).timetuple()) Is it possible for this to produce
Given the following code $c= new SoapClient('http://www.webservicex.net/CurrencyConvertor.asmx?WSDL'); $usa = USD; $eng = GBP; doing
Given the Following Code how Would i Change/Set my Silverlight WCF Service URI in

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.