<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Program with a GUI crashes when add .h and .cpp files]]></title><description><![CDATA[<p dir="auto">Hello! I'm working on a program that uses multiple classes and a GUI. The thing is that I want to make an extra file where all the global variables, whose values are constant and are used in all the program. This file I did it by creating a header where I define the type of each variable and in a .cpp, I give it the value  to each variable. The problem is that before creating the .h and .cpp files the program ran without any problems, but when I add these files the  program crashes.</p>
<pre><code>#ifndef CONSTANTESRADARGUI_H
#define CONSTANTESRADARGUI_H

//VARIABLES GLOBALES CON UN VALOR CONSTANTE
//se ponen todas las variables globales que se utilizan en todo el programa y su valor es constante
//las variables se inicializan en constantesradargui.cpp

//----------------------------
//parametros del radar
extern float freqM;         //frecuencia de muestreo, en m/s
extern int nBI;             //frecuencia de bearing increment BI, en Hz   no se usa
extern int nTRG;            //frecuencia de trigger TRG, en Hz    2037
extern int rpmHM;           //frecuencia del hearing mark HM, en rpm

//----------------------------
//parametros de la matriz M
extern int  nfilas;         //cantidad de filas de la matriz M
extern int numeroColumna;   //para modificar tamaño de la matriz (Lucas Pordomingo)
                            //numeroColumna=1 para cantidad de columnas calculadas con parametros del radar
                            //numeroColumna=2 para cantidad de columnas de 4096
                            //numeroColumna=3 para cantidad de columnas de 2096


//----------------------------
//parametros calculados a partir de los parametros del radar
extern int VelGiro;             //velocidad con la que gira el radar
extern int ncolumnas;           //numero de columnas de la matriz M, con los datos del radar
extern int tamano_columna;      //sirve para modificar distancia de graficado desde el centro del radar
//tamano_columna = 1/(ncolumnas/8183) y ncolumnas= int(round((1/nTRG)*(freqM*1000000))), para el caso de usar una matriz M cantidad de  columnas de acuerdo a los parametros del radar
//tamano_columna = 2 y ncolumnas = 4096, para el caso de usar una matriz M con 4096 columnas
//tamano_columna = 4 y ncolumnas = 2096, para el caso de usar una matriz M con 2096 columnas

//----------------------------
//constantes que se utilizan en varios lugares del programa
extern int niveles;        //colores
extern float area;         //area del pixel que se dibuja
extern float kmmilla;
extern float rmillamuestra;
extern float rfilaangulo;

#endif // CONSTANTESRADARGUI_H
</code></pre>
<pre><code>#include&lt;constantesradargui.h&gt;

#include&lt;math.h&gt;

//----------------------------
//parametros del radar
float freqM= 16.666;         //frecuencia de muestreo, en m/s
int nBI= 2049;               //frecuencia de bearing increment BI, en Hz   no se usa
int nTRG= 2037;              //frecuencia de trigger TRG, en Hz    2037
int rpmHM= 25;               //frecuencia del hearing mark HM, en rpm

//----------------------------
//parametros de la matriz M
int nfilas= 4096;         //cantidad de filas de la matriz M
int numeroColumna= 1;    //para modificar tamaño de la matriz (Lucas Pordomingo)
                         //numeroColumna=1 para cantidad de columnas calculadas con parametros del radar
                         //numeroColumna=2 para cantidad de columnas de 4096
                         //numeroColumna=3 para cantidad de columnas de 2096

//----------------------------
//parametros calculados a partir de los parametros del radar
int VelGiro= (1/(rpmHM*0.02));;                        //velocidad con la que gira el radar
int ncolumnas= int(round((1/nTRG)*(freqM*1000000)));      //numero de columnas de la matriz M, con los datos del radar
int tamano_columna =1/(ncolumnas/8183);                   //sirve para modificar distancia de graficado desde el centro del radar
//tamano_columna = 1/(ncolumnas/8183) y ncolumnas= int(round((1/nTRG)*(freqM*1000000))), para el caso de usar una matriz M cantidad de  columnas de acuerdo a los parametros del radar
//tamano_columna = 2 y ncolumnas = 4096, para el caso de usar una matriz M con 4096 columnas
//tamano_columna = 4 y ncolumnas = 2096, para el caso de usar una matriz M con 2096 columnas

//----------------------------
//constantes que se utilizan en varios lugares del programa
int niveles = 5;        //colores
float area = 0.1;       //area del pixel que se dibuja
float kmmilla=1.852;
float rmillamuestra = (1 / (freqM * 1000000)) * (300000 / kmmilla);
float rfilaangulo= nfilas/360;
</code></pre>
<p dir="auto">The errror is:<br />
09:55:09: Starting /home/pc2/Descargas/build-Radar-Desktop-Debug/Radar...<br />
09:55:10: /home/pc2/Descargas/build-Radar-Desktop-Debug/Radar crashed.</p>
]]></description><link>https://forum.qt.io/topic/139369/program-with-a-gui-crashes-when-add-h-and-cpp-files</link><generator>RSS for Node</generator><lastBuildDate>Sun, 25 Oct 2026 23:55:22 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/139369.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 16 Sep 2022 13:07:57 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Program with a GUI crashes when add .h and .cpp files on Tue, 20 Sep 2022 07:52:53 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/pordo">@<bdi>Pordo</bdi></a> said in <a href="/post/729360">Program with a GUI crashes when add .h and .cpp files</a>:</p>
<blockquote>
<p dir="auto">I resolved it changing the variable type to float.</p>
</blockquote>
<p dir="auto">That sounds a lot more useful :)<br />
Just a comment: consider using <code>double</code> instead of <code>float</code> for this, other constants and arithmetic.  In C all floating point calculations are done in <code>double</code>-precision anyway (at least I <em>think</em>/<em>thought</em> this was the case).  Using <code>float</code> instead of <code>double</code> throws away precision for no good reason.  The only time I would use <code>float</code>s is to save space if I had millions of them....</p>
]]></description><link>https://forum.qt.io/post/729410</link><guid isPermaLink="true">https://forum.qt.io/post/729410</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Tue, 20 Sep 2022 07:52:53 GMT</pubDate></item><item><title><![CDATA[Reply to Program with a GUI crashes when add .h and .cpp files on Mon, 19 Sep 2022 20:49:27 GMT]]></title><description><![CDATA[<p dir="auto">Hello, I was reading their answers and tried to comment  a section of the code that uses the variable tamano_columa. The code compiles, so I confirm that the problem was there.<br />
The variable is used to maintain a distance ratio on a  graphic. I resolved it changing the variable type to float.<br />
Thanks to everyone for their answers, they were helpful.</p>
]]></description><link>https://forum.qt.io/post/729360</link><guid isPermaLink="true">https://forum.qt.io/post/729360</guid><dc:creator><![CDATA[Pordo]]></dc:creator><pubDate>Mon, 19 Sep 2022 20:49:27 GMT</pubDate></item><item><title><![CDATA[Reply to Program with a GUI crashes when add .h and .cpp files on Sat, 17 Sep 2022 13:22:54 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/paul-colby">@<bdi>Paul-Colby</bdi></a> said in <a href="/post/729101">Program with a GUI crashes when add .h and .cpp files</a>:</p>
<blockquote>
<p dir="auto"><code>int tamano_columna =1/(ncolumnas/8183.0);</code></p>
</blockquote>
<p dir="auto">Good job for working through <a class="plugin-mentions-user plugin-mentions-a" href="/user/pordo">@<bdi>Pordo</bdi></a>'s code to come to this!  Indeed this will prevent the crash --- provided <code>ncolumnas != 8183.0</code>!  But <a class="plugin-mentions-user plugin-mentions-a" href="/user/pordo">@<bdi>Pordo</bdi></a> <em>may</em> have a deeper logic problem in this statement.</p>
<p dir="auto">Since the result is assigned to an <code>int</code>, there is a "limited" set of possibilities for what the <code>1 / something</code> on the right-hand side will evaluate to anyway:</p>
<ul>
<li>if <code>something == 0</code>, it will crash/be undefined.</li>
<li>if <code>something &gt;= 1</code>, for any value of <code>something</code> then <code>1 / something</code> will evaluate to <code>0</code> as a (truncated) integer.</li>
<li>if and only if <code>0 &lt; something &lt; 1</code> will it produce any <code>int</code> great than <code>0</code>.  Which means that for <code>something</code>, in the <code>(ncolumnas/8183.0)</code> expression <code>ncolumnas</code> needs to be a <em>lot</em> less than <code>8183.0</code> <em>if this is the intention</em>.  Is it?  Else I wonder what OP is expecting the value of <code>tamano_columna</code> to be?</li>
</ul>
]]></description><link>https://forum.qt.io/post/729105</link><guid isPermaLink="true">https://forum.qt.io/post/729105</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Sat, 17 Sep 2022 13:22:54 GMT</pubDate></item><item><title><![CDATA[Reply to Program with a GUI crashes when add .h and .cpp files on Sat, 17 Sep 2022 11:45:55 GMT]]></title><description><![CDATA[<p dir="auto">Hi <a class="plugin-mentions-user plugin-mentions-a" href="/user/pordo">@<bdi>Pordo</bdi></a>,</p>
<p dir="auto">There's probably other things, but this line crashes with a floating-point exception on my machine:</p>
<pre><code>int tamano_columna =1/(ncolumnas/8183);
</code></pre>
<p dir="auto">The reason is that <code>ncolumnas</code> (from the preceding line) evaluates to <code>8182</code>.  And since all the values (both variables and literals) in that statement are integers, it evaluates like this:</p>
<pre><code>int tamano_columna =1/(ncolumnas/8183);
                   =1/(8182/8183);
                   =1/trunc(0.99987779543);
                   =1/0;
                   =exception
</code></pre>
<p dir="auto">You can fix this particular exception by making either <code>ncolumnas</code> or the <code>8183</code> literal a <code>float</code> or <code>double</code>; eg this does not crash for me:</p>
<pre><code>int tamano_columna =1/(ncolumnas/8183.0);
</code></pre>
<p dir="auto">But as <a class="plugin-mentions-user plugin-mentions-a" href="/user/christian-ehrlicher">@<bdi>Christian-Ehrlicher</bdi></a> said, the debugger is your friend :)</p>
<p dir="auto">Cheers.</p>
]]></description><link>https://forum.qt.io/post/729101</link><guid isPermaLink="true">https://forum.qt.io/post/729101</guid><dc:creator><![CDATA[Paul Colby]]></dc:creator><pubDate>Sat, 17 Sep 2022 11:45:55 GMT</pubDate></item><item><title><![CDATA[Reply to Program with a GUI crashes when add .h and .cpp files on Fri, 16 Sep 2022 15:40:21 GMT]]></title><description><![CDATA[<p dir="auto">Use a debugger and see where exactly it crashes.</p>
]]></description><link>https://forum.qt.io/post/729051</link><guid isPermaLink="true">https://forum.qt.io/post/729051</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Fri, 16 Sep 2022 15:40:21 GMT</pubDate></item></channel></rss>