Results 1 to 3 of 3

Thread: java class

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default java class

    Hello,
    I'm new to java and I have this problem:
    Qt Code:
    1. public class Name {
    2. String name = null;
    3. }
    4.  
    5. Vector<Name> gn = new Vector<Name>();
    6. gn.add (new Name("mike") ); // for 10 times
    7. String name = "Sam";
    8. int idx = gn.indexOf( new Name( name )); //this not work
    To copy to clipboard, switch view to plain text mode 
    Now the problem is probably clear to you; I need to retrieve the idx having that class. Any helps?

    thanks,
    Regards

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: java class

    My java is getting rusty, but I think you need to implement equals for your class. Otherwise you end up comparing pointers which are different for each call of new.

    HTH

  3. #3
    Join Date
    Jul 2009
    Posts
    13
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: java class

    in addition to implementing equals ( previous reply ) you need a constructor for Name that will set the name member variable.

    class Name {
    ...
    public Name(String name) {
    this.name = name;
    }
    ...
    }

Similar Threads

  1. is there a class in QT4 like robot class of java
    By sathyanarayanan in forum Qt Programming
    Replies: 1
    Last Post: 18th February 2009, 11:25
  2. class in the class
    By baray98 in forum General Programming
    Replies: 2
    Last Post: 23rd July 2008, 07:01
  3. class QHBoxLayout
    By csvivek in forum Installation and Deployment
    Replies: 2
    Last Post: 10th April 2008, 07:57
  4. How to use Signal through direct connection
    By santosh.kumar in forum Qt Programming
    Replies: 1
    Last Post: 14th December 2007, 07:07
  5. Replies: 2
    Last Post: 4th May 2006, 19:17

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.