First of all, forget about extern
. You don't need to use it. Period. Really.
The "initialization" you wrote for the edits
member is also incorrect. We're in C++11 age, you can assign an initializer list, and this is not C so you shouldn't be using naked C arrays.
Thus, your member definition should be
std::array<QLineEdit*, 2> m_edits;
and you should assign to it as follows:
m_edits = {{ ui.edit1, ui.edit2 }};
Note that you don't really want to hold Ui::Setup
through a pointer, even if silly Qt Creator template code does it. Hold it by value.
The following is a complete example:
#include <QtWidgets>
#include <array>
// This is what uic would generate from a simple .ui file.
namespace Ui {
struct Source {
QLineEdit * edit1, * edit2;
void setupUi(QWidget * parent) {
edit1 = new QLineEdit{parent};
edit2 = new QLineEdit{parent};
}
};
}
class Source : public QWidget {
Ui::Source ui;
std::array<QLineEdit*, 2> m_edits;
public:
Source() {
ui.setupUi(this);
m_edits = {{ ui.edit1, ui.edit2 }};
Q_ASSERT(m_edits[0] == ui.edit1);
Q_ASSERT(m_edits[1] == ui.edit2);
}
};
int main(int argc, char ** argv) {
QApplication app{argc, argv};
Source source;
return 0;
}