Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. cannot connect (null)
Qt 6.11 is out! See what's new in the release blog

cannot connect (null)

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 4.8k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lorence
    wrote on last edited by Lorence
    #1

    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 froms

    But when I do

    connect(ui->playableTile1,SIGNAL(pushTile()),this,SLOT(pushTile());
    I'm not getting any erorr

    1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      @Lorence said:

      std::array<PlayableTile*,2>tile
      { {
      ui->playableTile1;
      ui->playableTile2;
      }. };

      That looks like a typo. What's your actual code?

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • L Offline
        L Offline
        Lorence
        wrote on last edited by
        #3

        Sorry for the late reply and yes it's a typo sorry, I'm just typing on my phone because my PC has a problem on connection

        Its an array, the first semicolon is a comma and forget the second one, I edited it

        1 Reply Last reply
        0
        • JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          What do you get when you call this?:

          #include <QDebug>
          
          // ...
          
          qDebug() << tile[0];
          

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          0
          • L Offline
            L Offline
            Lorence
            wrote on last edited by
            #5

            Sorry again for the late reply, i was so busy but now im free

            What do you get when you call this?:
            This is what i get
            QObject(0x0)

            JKSHJ 1 Reply Last reply
            0
            • L Lorence

              Sorry again for the late reply, i was so busy but now im free

              What do you get when you call this?:
              This is what i get
              QObject(0x0)

              JKSHJ Offline
              JKSHJ Offline
              JKSH
              Moderators
              wrote on last edited by
              #6

              @Lorence said:

              Sorry again for the late reply, i was so busy but now im free

              That's OK :)

              This is what i get
              QObject(0x0)

              You have a null pointer.

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              1 Reply Last reply
              0
              • L Offline
                L Offline
                Lorence
                wrote on last edited by
                #7

                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?

                1 Reply Last reply
                0
                • mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by SGaist
                  #8

                  Hi
                  well if you do

                  std::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 after ui->setupUi ( this );

                  [edit: fixed coding tags SGaist]

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved