Results 1 to 5 of 5

Thread: In need of an advice of simple line drawing with Qt

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default In need of an advice of simple line drawing with Qt

    Hello!

    I am a complete newbie what comes to Qt C++ programming. My assignment would be to draw a simple line in a QWidget and frankly I don't know what all I ought to be aware of (header files, QObject...etc) in order to complete this task. I am sorry if this question is answered elsewhere on the forum, yet I couldn't find a solution from here or any Qt related forums nor the Web. I am using QT 4.6.2 and a Qt Creator 1.3.1 on Windows Vista.

    I have a designer form, in which I have promoted a class "paint" and created after a header file "paint.h"


    The header file (paint.h) looks like:

    Qt Code:
    1. #ifndef PAINT_H
    2. #define PAINT_H
    3.  
    4. #include <QWidget>
    5.  
    6. class paint : public QWidget
    7. {
    8. Q_OBJECT
    9.  
    10. public:
    11. paint(QWidget *parent = 0);
    12.  
    13. protected:
    14. void paintEvent(QPaintEvent *event);
    15.  
    16. };
    17.  
    18.  
    19. #endif // PAINT_H
    To copy to clipboard, switch view to plain text mode 

    and I have a source file:

    Qt Code:
    1. #include "paint.h"
    2. #include <QApplication>
    3. #include <QPainter>
    4. #include <QLineF>
    5.  
    6.  
    7. void QWidget::paintEvent ( QPaintEvent * event )
    8. {
    9.  
    10. QLineF line(10.0, 80.0, 90.0, 20.0);
    11.  
    12. QPainter painter(this);
    13. painter.drawLine(line);
    14.  
    15. }
    To copy to clipboard, switch view to plain text mode 

    Yet this wholeness is invalid and I'm not sure what things are wrong with this. The compiler output looks as following:

    Qt Code:
    1. .../harjoitus2/draw_line/line1.cpp:7: warning: 'virtual void QWidget::paintEvent(QPaintEvent*)' redeclared without dllimport attribute: previous dllimport ignored
    2.  
    3. c:\Qt\2010.02.1\qt\lib/libqtmaind.a:-1: error: In function `WinMain@16':
    4.  
    5. C:\qt-greenhouse\Trolltech\Code_less_create_more\Trolltech\Code_less_create_more\Troll\4.6\qt\src\winmain/qtmain_win.cpp:131: undefined reference to `qMain(int, char**)'
    6.  
    7. :-1: error: collect2: ld returned 1 exit status
    To copy to clipboard, switch view to plain text mode 

    I would be very grateful if you would point me out the essential facts of making this simple program to function. Thanks in advance!
    Last edited by Arvelua; 15th March 2010 at 11:55.

Similar Threads

  1. Replies: 8
    Last Post: 8th October 2009, 16:59
  2. Drawing line on table
    By kocakden in forum Qt Programming
    Replies: 7
    Last Post: 29th April 2008, 09:50
  3. drawing an unfixed line?
    By tommy in forum Newbie
    Replies: 7
    Last Post: 26th January 2008, 17:18
  4. Line drawing in Designer
    By Doug Broadwell in forum Newbie
    Replies: 8
    Last Post: 28th March 2007, 00:02
  5. Line drawing
    By kiranraj in forum Qt Programming
    Replies: 1
    Last Post: 29th January 2007, 06:38

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.