cannot connect (null)
-
I have an array of type Tile which inherits QLabel
std::array<PlayableTile*,2>tile
{ {
ui->playableTile1,
ui->playableTile2
} };
Error: cannot connect (null)::pushTile() to MainWindow::pushTile()connect(tile[0],SIGNAL(pushTile()),this,SLOT(pushTile());
....................^ this is where the error come fromsBut when I do
connect(ui->playableTile1,SIGNAL(pushTile()),this,SLOT(pushTile());
I'm not getting any erorr -
What do you get when you call this?:
#include <QDebug> // ... qDebug() << tile[0];
-
I fixed it by doing this
std::array<PlayableTile*,5> playableTileArray;
playableTileArray[0] = ui->playableTile1; playableTileArray[1] = ui->playableTile2; playableTileArray[2] = ui->playableTile3; playableTileArray[3] = ui->playableTile4; playableTileArray[4] = ui->playableTile5;
C++ is now kicking me just because i havent programmed for 2 weeks.
can you explain to me why this works?You have a null pointer.
I dont get it, why i have a null pointer? -
Hi
well if you dostd::array<PlayableTile*,2>tile { { ui->playableTile1; ui->playableTile2; }. };
in Class def. (the h file)
then its very likely that this list is init'ed up BEFORE the
ui->setupUi ( this )
;
in the constructor so you are adding NULL pointers.
So it's best to add them explicit and not use init lists to be on the safe side.
So before ui->setupUi ( this ); Nothing is setup yet.
You second example works as you do not use init list anymore so I bet
playableTileArray[0] = ui->playableTile1;
is afterui->setupUi ( this )
;[edit: fixed coding tags SGaist]