Page 2 of 2 FirstFirst 12
Results 21 to 35 of 35

Thread: Painting lines

  1. #21
    Join Date
    Feb 2006
    Posts
    87
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Painting lines

    how do i construct a list og edges then..i looked at the linked list library but then i got confused with qvector aswell..which one do i use?

  2. #22
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Painting lines

    Quote Originally Posted by therealjag
    how do i construct a list og edges then..i looked at the linked list library but then i got confused with qvector aswell..which one do i use?
    It depends. You can add items to the list faster, but accessing elements randomly is much slower than in vector. If you plan to add a lot of items and you will only read the whole list at once, you should use linked list. If you will access single items, you should use a vector. There is also a QList which is something between linked list and a vector.

  3. #23
    Join Date
    Feb 2006
    Posts
    87
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Painting lines

    hey again i was thinking of using an array of structs where my struct would be:

    struct Link{

    int n1;
    int n2;
    int capacity
    }

    how would i create an array of this??

  4. #24
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Painting lines

    Qt Code:
    1. QVector<Link> links;
    To copy to clipboard, switch view to plain text mode 

  5. #25
    Join Date
    Mar 2006
    Location
    India
    Posts
    15
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Thumbs up Re: Painting lines

    no offense, but you really ought to learn some basics of data structures. there's no point in learning qt data-structures without knowing basic DS theory.

    it is a bit like learning to use the harpoon, without knowing what a whale is

    grab a text book on data-structures; trust me, it will go a long way to ease programming.
    Qt 4.2 (qt-copy in KDE svn)
    KDE 4.0 (svn)
    Currently developing Anthias

  6. #26
    Join Date
    Feb 2006
    Posts
    87
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Painting lines

    no offense, but you really ought to learn some basics of data structures. there's no point in learning qt data-structures without knowing basic DS theory.

    it is a bit like learning to use the harpoon, without knowing what a whale is
    yeah you're probably right but its a project im doing and i dont have much time to do it which is why i havent gone about it the proper way. i guess in the summer i could read to my hearts content and not bother you guys all the time

  7. #27
    Join Date
    Feb 2006
    Posts
    87
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Painting lines

    hey there i tried using the QVector to make my struct into an array but the program crashes when i try to run it. it compiles ok but there seems to be a problem with the way i am referencing the QVector...heres my code below:

    Qt Code:
    1. links[0].n2 = QInputDialog::getInteger(this, tr("QInputDialog::getInteger()"),
    2. tr("enter second node to link:"), 25, 0, 100, 1, &ok);
    3.  
    4. if(ok)
    5. integerLabel->setText(tr("%1").arg(links[0].n2));
    To copy to clipboard, switch view to plain text mode 

    any help would be much appreciated again

  8. #28
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Painting lines

    void QVector::append ( const T & value )
    Inserts value at the end of the vector.

  9. #29
    Join Date
    Feb 2006
    Posts
    87
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Painting lines

    hey there i tried .append() but it still didnt work. i get an error saying:

    "not enough contextual info to determine type"
    i tried it with the following piece of code:

    Qt Code:
    1. links.capacity.append(topology[n1][n2]);
    To copy to clipboard, switch view to plain text mode 

    what am i doing wrong?

  10. #30
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Painting lines

    Quote Originally Posted by therealjag
    links.capacity.append(topology[n1][n2]);
    What types do the links and links.capacity have?

  11. #31
    Join Date
    Feb 2006
    Posts
    87
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Painting lines

    links is just my struct Link and it contains the integer which is called capacity..
    my struct is shown below:

    Qt Code:
    1. struct Link{
    2.  
    3. int n1;
    4. int n2;
    5. int capacity;
    6. }
    To copy to clipboard, switch view to plain text mode 
    the 2-d array is just an integer as well

  12. #32
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Painting lines

    int doesn't have an append() method. You probably wanted to invoke that method on some other object.

  13. #33
    Join Date
    Feb 2006
    Posts
    87
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Painting lines

    int doesn't have an append() method.
    ok, so how do i add that number from topology[n1][n2] to link.capacity? i also tried insert() with my code instead of append and it still didnt work??

  14. #34
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Painting lines

    Quote Originally Posted by therealjag
    ok, so how do i add that number from topology[n1][n2] to link.capacity? i also tried insert() with my code instead of append and it still didnt work??
    What do you mean by "add"? capacity in an integer and it can hold only one value. You should create a list or vector and add values to it.

  15. #35
    Join Date
    Feb 2006
    Posts
    87
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Painting lines

    What do you mean by "add"? capacity in an integer and it can hold only one value. You should create a list or vector and add values to it.
    oh sorry i was a bit unclear i just want the value at capacity[n1][n2] to be equal to one of the instances in my vector 'links' and i want it to be stored into link.capacity?

Similar Threads

  1. how do i know if two lines intersect?
    By Vincenzo in forum Newbie
    Replies: 4
    Last Post: 7th November 2008, 14:23
  2. I want to get lines of text
    By newplayer in forum Qt Programming
    Replies: 11
    Last Post: 29th July 2008, 09:03
  3. Display QLabel in two lines
    By arunvv in forum Newbie
    Replies: 1
    Last Post: 8th February 2008, 05:25
  4. Slow painting in QGraphicsView
    By JonathanForQT4 in forum Qt Programming
    Replies: 12
    Last Post: 16th July 2007, 09:54
  5. How to draw lines with the right width?
    By albanelporto in forum Qt Programming
    Replies: 3
    Last Post: 22nd November 2006, 11:51

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.