Results 1 to 20 of 35

Thread: Painting lines

Hybrid View

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

    Default Re: Painting lines

    Quote Originally Posted by therealjag
    ru talking about an array or an array of structs of some sort? i was thinking about using linked lists but im not very sure about using them in qt...
    There are many options. You can keep a list of nodes and each node can contain a list of edges. You can also keep a list of nodes and a list of edges.

    First think what data you need to store and how would you like to access it, then choose a data structure that fits the best.

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

    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?

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

    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.

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

    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??

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

    Default Re: Painting lines

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

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

    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

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

    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

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

    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

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

    Default Re: Painting lines

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

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

    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?

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

    Default Re: Painting lines

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

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

    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

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

    Default Re: Painting lines

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

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
  •  
Qt is a trademark of The Qt Company.