#include <QtGui>int main( int argc, char **argv ){ QApplication app( argc, argv ); QImage image( 300,200, QImage::Format_RGB32 ); image.fill(0xFFFFFF); QPainter painter( &image ); painter.drawText(100,100,"Hello, world!"); image.save( "test.png", "PNG" ); return 0;}
TEMPLATE = appCONFIG += consoleSOURCES = test.cpp
int main( int argc, char **argv ){ QCoreApplication app( argc, argv ); QImage image( 300,200, QImage::Format_RGB32 ); image.fill(0xFFFFFF); QPainter painter( &image ); painter.drawText(100,100,"Hello, world!"); image.save( "test.png", "PNG" ); return 0;}
#include <QImage>#include <QPainter>#include <QApplication>int main( int argc, char** argv ){ QApplication app( argc, argv, false ); QImage image( 400, 300, QImage::Format_RGB32 ); QFont font( "Helvetica", 24 ); QPainter painter( &image ); painter.setFont( font ); painter.setPen( Qt::black ); painter.fillRect( image.rect(), Qt::white ); painter.drawText( image.rect(), Qt::AlignCenter, "Hello, world!" ); image.save( "test.png", "PNG" ); return 0;}
#include <QImage>#include <QPainter>#include <QApplication>...QApplication app( argc, argv, false );...
#include <QApplication>#include <QImage>#include <QPainter>#include <qwt_plot.h>#include <qwt_plot_curve.h>#include <qwt_plot_grid.h>#include <qwt_legend.h>static void output( QwtPlot *plot ){ const int width = 600; const int height = 400; QImage image( width,height, QImage::Format_RGB32 ); image.fill(0xFFFFFF); QPainter painter( &image ); plot->print( &painter, QRect(10,10,width-20,height-20) ); image.save( "test.png", "PNG" );}static void setData( QwtPlotCurve *curve ){ QVector<double> x,y; for(int i=0;i<1000;i++) { x << i; y << sin((double)i/1000*2*3.1415926); } curve->setData( x,y );}int main( int argc, char **argv ){ QApplication app( argc, argv, true ); QwtPlot plot; QwtPlotGrid grid; grid.enableXMin(true); grid.enableYMin(true); grid.setMajPen(QPen(Qt::black, 1, Qt::DotLine)); grid.setMinPen(QPen(Qt::gray, 1, Qt::DotLine)); grid.attach( &plot ); plot.setCanvasBackground(QColor("linen")); plot.setAxisScale(QwtPlot::yLeft,-1,1); plot.insertLegend(new QwtLegend, QwtPlot::BottomLegend); QwtPlotCurve curve; curve.setPen(QPen(Qt::darkBlue,2)); curve.setTitle("sin"); setData( &curve ); curve.attach( &plot ); app.processEvents(); output( &plot ); return 0;}
TEMPLATE = appCONFIG += consoleSOURCES = test.cppwin32{INCLUDEPATH += $$[QT_INSTALL_PREFIX]/include/QwtLIBS += -lqwt5 }unix{INCLUDEPATH += /usr/local/qwt/includeLIBS += -lqwt}
QWidget: Cannot create a QWidget when no GUI is being usedThis application has requested the Runtime to terminate it in an unusual way.Please contact the application's support team for more information.