PDA

View Full Version : In need of an advice of simple line drawing with Qt



Arvelua
15th March 2010, 12:49
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:



#ifndef PAINT_H
#define PAINT_H

#include <QWidget>

class paint : public QWidget
{
Q_OBJECT

public:
paint(QWidget *parent = 0);

protected:
void paintEvent(QPaintEvent *event);

};


#endif // PAINT_H


and I have a source file:



#include "paint.h"
#include <QApplication>
#include <QPainter>
#include <QLineF>


void QWidget::paintEvent ( QPaintEvent * event )
{

QLineF line(10.0, 80.0, 90.0, 20.0);

QPainter painter(this);
painter.drawLine(line);

}


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


.../harjoitus2/draw_line/line1.cpp:7: warning: 'virtual void QWidget::paintEvent(QPaintEvent*)' redeclared without dllimport attribute: previous dllimport ignored

c:\Qt\2010.02.1\qt\lib/libqtmaind.a:-1: error: In function `WinMain@16':

C:\qt-greenhouse\Trolltech\Code_less_create_more\Trollte ch\Code_less_create_more\Troll\4.6\qt\src\winmain/qtmain_win.cpp:131: undefined reference to `qMain(int, char**)'

:-1: error: collect2: ld returned 1 exit status


I would be very grateful if you would point me out the essential facts of making this simple program to function. Thanks in advance! :)

wysota
15th March 2010, 12:54
It should be paint::paintEvent(...) in line #7 of the second code snippet.

Arvelua
15th March 2010, 13:07
Thanks for your reply!

I corrected the line #7, but yet I get these error messages:


c:\Qt\2010.02.1\qt\lib/libqtmaind.a:-1: error: In function `WinMain@16':

C:\qt-greenhouse\Trolltech\Code_less_create_more\Trollte ch\Code_less_create_more\Troll\4.6\qt\src\winmain/qtmain_win.cpp:131: undefined reference to `qMain(int, char**)'

:-1: error: collect2: ld returned 1 exit status

wysota
15th March 2010, 13:13
Did you implement the main() function in your program? Be sure to add the file containing it to your project.

Arvelua
15th March 2010, 13:52
Yes, I did it now and the program works as espected. Thanks for your help. :)