<?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[Getting errors in QtCreator ui.h file]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">I needed to have the ability to copy/paste from a QTableWidget to a text file.  So what I did was created a CustomTableWidget which inherits from QTableWidget.  After I created my custom class in Qt creator, I promoted the custom class to the QTableWidgets I created in QtCreator.  When I try to compile I get errors in the source that calls the custom class ui_MyForm.h.  This file is generated by Qt.</p>
<p dir="auto">I keep getting emConfigTableWidget is undeclared in this .h file.</p>
<p dir="auto">I use my custom class like this:<br />
In .h file of my main source file.<br />
CustomTableWidget *emConfigTableWidget;</p>
<p dir="auto">In the CPP file I use it as such:<br />
#include "ui_MyForm.h"<br />
#include "CustomTableWidget.h"</p>
<p dir="auto">MyForm(QWidget *parent) :<br />
QWidget(parent),<br />
emConfigTableWidget(new CustomTableWidget)</p>
<p dir="auto">emConfigTableWidget-&gt;horizontalHeader()-&gt;setSectionResizeMode(EM_CONFIG_ID_INDEX, QHeaderView::ResizeToContents);</p>
<p dir="auto">But I get errors in ui_MyForm.h<br />
emConfigTableWidget:undeclared identifier</p>
<p dir="auto">Would anyone know why this is happening?</p>
<p dir="auto">My Custom class looks like this:<br />
CustomTableWidget.h<br />
#ifndef CUSTOMTABLEWIDGET_H<br />
#define CUSTOMTABLEWIDGET_H</p>
<p dir="auto">HIDE_QT_WARNINGS_START</p>
<p dir="auto">#include &lt;QTableWidget&gt;<br />
#include &lt;QObject&gt;</p>
<pre><code>    class CustomTableWidget : public QTableWidget
    {
         Q_OBJECT

    public:
        CustomTableWidget(QWidget *parent = 0);
        ~CustomTableWidget();
        void copy();
        void paste();

    private:
        QTableWidgetSelectionRange selectedRange();

    };
</code></pre>
<p dir="auto">#endif // CUSTOMTABLEWIDGET_H</p>
<p dir="auto">CustomTableWidget.cpp looks like this:<br />
#include "CustomTableWidget.h"<br />
#include &lt;QString&gt;<br />
#include &lt;QDebug&gt;<br />
#include &lt;QApplication&gt;<br />
#include &lt;QClipboard&gt;<br />
#include &lt;QTableWidgetSelectionRange&gt;</p>
<p dir="auto">CustomTableWidget(QWidget *parent) :<br />
QTableWidget(parent)<br />
{</p>
<p dir="auto">}</p>
<p dir="auto">~CustomTableWidget()<br />
{</p>
<p dir="auto">}</p>
<p dir="auto">void<br />
CustomTableWidget::copy()<br />
{<br />
QTableWidgetSelectionRange range = selectedRange();<br />
QString str;<br />
for (int i = 0; i &lt; range.rowCount(); ++i) {<br />
if (i &gt; 0)<br />
str += "\n";<br />
for (int j = 0; j &lt; range.columnCount(); ++j) {<br />
if (j &gt; 0)<br />
str += "\t";<br />
str += itemAt( range.topRow() + i, range.leftColumn() + j)-&gt;text();<br />
}<br />
}<br />
str += "\n";<br />
QApplication::clipboard()-&gt;setText(str);</p>
<p dir="auto">}</p>
<p dir="auto">QTableWidgetSelectionRange<br />
CustomTableWidget::selectedRange()<br />
{<br />
QList&lt;QTableWidgetSelectionRange&gt; ranges = selectedRanges();<br />
if(ranges.isEmpty())<br />
{<br />
return QTableWidgetSelectionRange();<br />
}</p>
<p dir="auto">return ranges.first();<br />
}</p>
<p dir="auto">void<br />
CustomTableWidget::paste()<br />
{<br />
QString str = QApplication::clipboard()-&gt;text();<br />
qDebug() &lt;&lt; str;<br />
QStringList rows = str.split('\n');<br />
int numRows = rows.count()-1;<br />
int numColumns = rows.first().count('\t') + 1;</p>
<pre><code>qDebug() &lt;&lt; numRows &lt;&lt; " " &lt;&lt; numColumns ;
for (int i = 0; i &lt; numRows; ++i)
{
    QStringList columns = rows[i].split('\t');
    for (int j = 0; j &lt; numColumns; ++j)
    {
          QApplication::clipboard()-&gt;setText(rows[i] + columns[j], QClipboard::Clipboard);
    }
}
</code></pre>
<p dir="auto">}</p>
]]></description><link>https://forum.qt.io/topic/139506/getting-errors-in-qtcreator-ui-h-file</link><generator>RSS for Node</generator><lastBuildDate>Sun, 25 Oct 2026 15:40:39 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/139506.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 22 Sep 2022 16:29:36 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Getting errors in QtCreator ui.h file on Thu, 22 Sep 2022 18:04:00 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/leinad">@<bdi>leinad</bdi></a> said in <a href="/post/729831">Getting errors in QtCreator ui.h file</a>:</p>
<blockquote>
<p dir="auto">I did a  clean and also reran run qmake.  Now I get "ui_myform.h" file not found.</p>
</blockquote>
<p dir="auto">Running the first make/build after this should run <code>uic</code> to regenerate this file in the debug or release directory, depending on which configuration you are building for.  Is it indeed doing so?  You should also be able to delete <em>all</em> the files in the debug/release directory (not the source one!) to restart from a really clean state.</p>
<p dir="auto">Get back to original state.  Find exactly which line in which file is causing <code>emConfigTableWidget is undeclared</code> message.  Figure out how you think <code>emConfigTableWidget</code> <em>should</em> have been declared to the compiler from that file or files which were included before it.</p>
]]></description><link>https://forum.qt.io/post/729833</link><guid isPermaLink="true">https://forum.qt.io/post/729833</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Thu, 22 Sep 2022 18:04:00 GMT</pubDate></item><item><title><![CDATA[Reply to Getting errors in QtCreator ui.h file on Thu, 22 Sep 2022 17:36:19 GMT]]></title><description><![CDATA[<p dir="auto">but indeed ui_myForm.h is in the debug folder so not sure why that error is occurring.</p>
]]></description><link>https://forum.qt.io/post/729832</link><guid isPermaLink="true">https://forum.qt.io/post/729832</guid><dc:creator><![CDATA[leinad]]></dc:creator><pubDate>Thu, 22 Sep 2022 17:36:19 GMT</pubDate></item><item><title><![CDATA[Reply to Getting errors in QtCreator ui.h file on Thu, 22 Sep 2022 17:32:43 GMT]]></title><description><![CDATA[<p dir="auto">I reversed them as you said but I still get the same results.  I did a  clean and also reran run qmake.  Now I get "ui_myform.h" file not found.</p>
]]></description><link>https://forum.qt.io/post/729831</link><guid isPermaLink="true">https://forum.qt.io/post/729831</guid><dc:creator><![CDATA[leinad]]></dc:creator><pubDate>Thu, 22 Sep 2022 17:32:43 GMT</pubDate></item><item><title><![CDATA[Reply to Getting errors in QtCreator ui.h file on Thu, 22 Sep 2022 16:54:07 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/leinad">@<bdi>leinad</bdi></a> said in <a href="/post/729826">Getting errors in QtCreator ui.h file</a>:</p>
<blockquote>
<p dir="auto">But I get errors in ui_MyForm.h<br />
emConfigTableWidget:undeclared identifier</p>
</blockquote>
<p dir="auto">If you get an error in a <code>.h</code> file show that line, and the lines around it.</p>
<pre><code>#include "ui_MyForm.h"
#include "CustomTableWidget.h"
</code></pre>
<blockquote>
<p dir="auto">But I get errors in ui_MyForm.h</p>
<p dir="auto">emConfigTableWidget:undeclared identifier</p>
</blockquote>
<p dir="auto">If <code>CustomTableWidget</code> is declared in <code>CustomTableWidget.h</code>, and that is included <em>after</em> <code>ui_MyForm.h</code>, and that has <code>CustomTableWidget *emConfigTableWidget;</code> in it, then what is <code>CustomTableWidget</code> at the time that statement is encountered?  Should those include lines be reversed?</p>
]]></description><link>https://forum.qt.io/post/729827</link><guid isPermaLink="true">https://forum.qt.io/post/729827</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Thu, 22 Sep 2022 16:54:07 GMT</pubDate></item></channel></rss>