Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8055149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:18:17+00:00 2026-06-05T08:18:17+00:00

I develop a cross platform Qt program which plots a polyline on a QGraphicsScene:

  • 0

I develop a cross platform Qt program which plots a polyline on a QGraphicsScene:

QPolygonF polygon;
//Init polygon here
for(int i = 0; i < (polygon.size()-1); i++) {
  float x1 = polygon[i].x();
  float y1 = polygon[i].y();
  float x2 = polygon[i+1].x();
  float y2 = polygon[i+1].y();
  QGraphicsLineItem* item = new QGraphicsLineItem(x2, y2, x1, y1);
  item->setPen(QPen(QBrush(color), 2));
  item->setZValue(30);
  item->setData(0, QVariant((int)value));
  addItem(item);
}

The program crashes on windows when it recieves the following values:

 float x1 = 249.573;
 float y1 = 183.471;
 float x2 = 303.983;
 float y2 = 183.45;

This polyline is composed of an almost horizontal line. The crash doesn’t occur when the line is horizontal or the absolute difference between y1 and y2 is 0 or larger than 0.5.
It doesn’t crash on Ubuntu.

When I change the polyline to a polygon the program doesn’t crash. My best, but ugly solution was to draw the polyline as a polygon – append the same points twice to the polygon:

QPolygonF polygon;
//Init polygon here
for(int i = polygon.size()-1; i > 0; i--) {
   QPointF point(polygon[i].x(), polygon[i].y());
   polygon.append(point);
}
QGraphicsPolygonItem* item = new QGraphicsPolygonItem(polygon);
item->setPen(QPen(QBrush(color), 2));
item->setZValue(30);
item->setData(0, QVariant((int)value));
addItem(item);

I tried to recreate the bug in a small and independent program, that plots a line with the same coordinates on a QGraphicScene. No crash was observed.

Why is this crash happening? Is there a more prettier solution to this bug?

By the way, the call stack in VS2008 debugger tells me that the crash is in malloc.c in msvcr90.dll which is called by QtGui4.dll.

Technicals:

Qt version: 4.7.0

OS: Windows 7 and Ubuntu

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T08:18:19+00:00Added an answer on June 5, 2026 at 8:18 am

    Did you know that there is also the QGraphicsPathItem? (QGraphicsPolygonItem is for closed polygons only, not for polylines. The path item is for general paths.)

    You need to construct a QPainterPath from your QPolygon:

    QPainterPath path;
    if(polygon.size() > 0) // check this, because we use [0] outside the loop!
    {
        path.moveTo(polygon[0]);
        for(int i = 1; i < polygon.size(); ++i) // starting from 1 (0 was a "moveTo")
           path.lineTo(polygon[i]);
    }
    

    Then make and use the path item:

    QGraphicsPathItem* item = new QGraphicsPathItem(path);
    
    // your additional code from above:
    item->setPen(QPen(QBrush(color), 2));
    item->setZValue(30);
    item->setData(0, QVariant((int)value));
    
    addItem(item);
    

    But note that since your posted code seems to be error-free, there has to be a serious bug in your program (probably at a different (maybe related) position in the code), which you should fix anyway!

    Probably there is a bug in the generation of the coordinates? Or some calculation even before generating the QPolygonF? Did you try commenting out the code which generates the item?

    You could also try using valgrind alternative for Windows. See this Stackoverflow question for some tools.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to develop a cross-platform application using C++ with boost. I typically program
I would like to develop a cross platform application, i'm not sure which is
Which is the best framework to develop cross platform application. Especially for android and
I am going to develop an application which will be cross platform and it
I am planning to develop an cross platform application in Java . I am
I program using PhoneGap and learned that cross-platform apps really produces slow applications compared
I am using phonegap and sqlite to develop cross-platform mobile app for android,ios,blackberry.For reference
I am planning to develop a cross-platform script. On Linux and other operating systems,
I am trying to use appcelerator to develop some cross platform mobile applications, but
In the interest of creating cross-platform code, I'd like to develop a simple financial

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.