Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Raspbian 2 player chess game
Forum Updated to NodeBB v4.3 + New Features

Raspbian 2 player chess game

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
56 Posts 4 Posters 9.4k Views 1 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.
  • Q Offline
    Q Offline
    Quantum1982
    wrote on last edited by
    #3

    Hi
    Thanks for your reply

    What formatting am I missing here ?

    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      Quantum1982
      wrote on last edited by
      #4

      Ok thanks

      But now there is a different error :

      #include "mainwindow.h"
      #include "ui_mainwindow.h"
      #include <QImage>
      #include "newstandardgame.h"
      #include <QPainter>
      #include <QRect>

      MainWindow::MainWindow(QWidget *parent)
      : QMainWindow(parent)
      , ui(new Ui::MainWindow)
      {
      ui->setupUi(this);

      QPainter * ChessPiece = new QPainter();
      QImage * Image = new QImage("C:/Users/User/Desktop/WhiteQueen.jpg");
      //Image->
      
      QRect Source;
      QRect Dest;
      
      Source.setCoords(0,0,30,30);
      Dest.setCoords(0,0,30,30);
      
      ChessPiece->drawImage(Dest,Image,Source);
      

      MainWindow::~MainWindow()
      {
      delete ui;
      }

      void MainWindow::on_NewStandardGame_clicked()
      {
      //NewStandardGame::show();
      }

      #include "mainwindow.h"
      #include "ui_mainwindow.h"
      #include <QImage>
      #include "newstandardgame.h"
      #include <QPainter>
      #include <QRect>

      MainWindow::MainWindow(QWidget *parent)
      : QMainWindow(parent)
      , ui(new Ui::MainWindow)
      {
      ui->setupUi(this);

      QPainter * ChessPiece = new QPainter();
      QImage * Image = new QImage("C:/Users/User/Desktop/WhiteQueen.jpg");
      //Image->
      
      QRect Source;
      QRect Dest;
      
      Source.setCoords(0,0,30,30);
      Dest.setCoords(0,0,30,30);
      
      ChessPiece->drawImage(Dest,Image,Source);
      

      MainWindow::~MainWindow()
      {
      delete ui;
      }

      void MainWindow::on_NewStandardGame_clicked()
      {
      //NewStandardGame::show();
      }
      C:\Desktop\ChessRaspbian\mainwindow.cpp:24: error: C2664: 'void QPainter::drawImage(int,int,const QImage &,int,int,int,int,Qt::ImageConversionFlags)': cannot convert argument 2 from 'QImage *' to 'const QImage &'
      ..\ChessRaspbian\mainwindow.cpp(24): note: Reason: cannot convert from 'QImage *' to 'const QImage'
      ..\ChessRaspbian\mainwindow.cpp(24): note: No constructor could take the source type, or constructor overload resolution was ambiguous

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        Quantum1982
        wrote on last edited by
        #5

        #include "mainwindow.h"
        #include "ui_mainwindow.h"
        #include <QImage>
        #include "newstandardgame.h"
        #include <QPainter>
        #include <QRect>
        #include <QString>

        MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::MainWindow)
        {
        ui->setupUi(this);

        QString ChessPieces[12];
        
        ChessPieces[0] = "C:/Users/User/Desktop/WhitePawn.jpg";
        ChessPieces[1] = "C:/Users/User/Desktop/WhiteRook.jpg";
        ChessPieces[2] = "C:/Users/User/Desktop/WhiteKnight.jpg";
        ChessPieces[3] = "C:/Users/User/Desktop/WhiteBishop.jpg";
        ChessPieces[4] = "C:/Users/User/Desktop/WhiteQueen.jpg";
        ChessPieces[5] = "C:/Users/User/Desktop/WhiteKing.jpg";
        ChessPieces[6] = "C:/Users/User/Desktop/BlackPawn.jpg";
        ChessPieces[7] = "C:/Users/User/Desktop/BlackRook.jpg";
        ChessPieces[8] = "C:/Users/User/Desktop/BlackKnight.jpg";
        ChessPieces[9] = "C:/Users/User/Desktop/BlackBishop.jpg";
        ChessPieces[10] = "C:/Users/User/Desktop/BlackQueen.jpg";
        ChessPieces[11] = "C:/Users/User/Desktop/BlackKing.jpg";
        
        
        
        QPainter * ChessPiece = new QPainter();
        QImage * Image = new QImage("C:/Users/User/Desktop/WhiteQueen.jpg");
        //Image->
        
        QRect Source;
        QRect Dest;
        
        Source.setCoords(0,0,30,30);
        Dest.setCoords(0,0,30,30);
        
        //QPainter *Painter = new QPainter();
        //Painter->drawImage(Dest,Image,Source);
        
        //const QPixmap Pixmap;
        
        //ChessPiece->drawImage(Dest,Image,Source);
        

        // ChessPiece->drawPixmap(0,0,30,30,Pixmap);

        }

        MainWindow::~MainWindow()
        {
        delete ui;
        }
        moc_mainwindow.obj:-1: error: LNK2019: unresolved external symbol "private: void __cdecl MainWindow::on_NewStandardGame_clicked(void)" (?on_NewStandardGame_clicked@MainWindow@@AEAAXXZ) referenced in function "private: static void __cdecl MainWindow::qt_static_metacall(class QObject *,enum QMetaObject::Call,int,void * *)" (?qt_static_metacall@MainWindow@@CAXPEAVQObject@@W4Call@QMetaObject@@HPEAPEAX@Z)

        JonBJ 1 Reply Last reply
        0
        • Q Quantum1982

          #include "mainwindow.h"
          #include "ui_mainwindow.h"
          #include <QImage>
          #include "newstandardgame.h"
          #include <QPainter>
          #include <QRect>
          #include <QString>

          MainWindow::MainWindow(QWidget *parent)
          : QMainWindow(parent)
          , ui(new Ui::MainWindow)
          {
          ui->setupUi(this);

          QString ChessPieces[12];
          
          ChessPieces[0] = "C:/Users/User/Desktop/WhitePawn.jpg";
          ChessPieces[1] = "C:/Users/User/Desktop/WhiteRook.jpg";
          ChessPieces[2] = "C:/Users/User/Desktop/WhiteKnight.jpg";
          ChessPieces[3] = "C:/Users/User/Desktop/WhiteBishop.jpg";
          ChessPieces[4] = "C:/Users/User/Desktop/WhiteQueen.jpg";
          ChessPieces[5] = "C:/Users/User/Desktop/WhiteKing.jpg";
          ChessPieces[6] = "C:/Users/User/Desktop/BlackPawn.jpg";
          ChessPieces[7] = "C:/Users/User/Desktop/BlackRook.jpg";
          ChessPieces[8] = "C:/Users/User/Desktop/BlackKnight.jpg";
          ChessPieces[9] = "C:/Users/User/Desktop/BlackBishop.jpg";
          ChessPieces[10] = "C:/Users/User/Desktop/BlackQueen.jpg";
          ChessPieces[11] = "C:/Users/User/Desktop/BlackKing.jpg";
          
          
          
          QPainter * ChessPiece = new QPainter();
          QImage * Image = new QImage("C:/Users/User/Desktop/WhiteQueen.jpg");
          //Image->
          
          QRect Source;
          QRect Dest;
          
          Source.setCoords(0,0,30,30);
          Dest.setCoords(0,0,30,30);
          
          //QPainter *Painter = new QPainter();
          //Painter->drawImage(Dest,Image,Source);
          
          //const QPixmap Pixmap;
          
          //ChessPiece->drawImage(Dest,Image,Source);
          

          // ChessPiece->drawPixmap(0,0,30,30,Pixmap);

          }

          MainWindow::~MainWindow()
          {
          delete ui;
          }
          moc_mainwindow.obj:-1: error: LNK2019: unresolved external symbol "private: void __cdecl MainWindow::on_NewStandardGame_clicked(void)" (?on_NewStandardGame_clicked@MainWindow@@AEAAXXZ) referenced in function "private: static void __cdecl MainWindow::qt_static_metacall(class QObject *,enum QMetaObject::Call,int,void * *)" (?qt_static_metacall@MainWindow@@CAXPEAVQObject@@W4Call@QMetaObject@@HPEAPEAX@Z)

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #6

          @Quantum1982
          At a guess: you used to have a slot method void MainWindow::on_NewStandardGame_clicked(). You seem to have removed its definition in your latest code. Has its declaration been removed from the class declaration in the .h file? Is there still a connect() referencing it? Maybe search your source files for on_NewStandardGame_clicked. Have you re-run qmake and done a full rebuild?

          1 Reply Last reply
          1
          • Q Offline
            Q Offline
            Quantum1982
            wrote on last edited by
            #7

            Thanks I fixed it.

            My newest problem is this :

            #include "mainwindow.h"
            #include "ui_mainwindow.h"
            #include <QImage>
            #include "newstandardgame.h"
            #include <QPainter>
            #include <QRect>
            #include <QString>

            MainWindow::MainWindow(QWidget *parent)
            : QMainWindow(parent)
            , ui(new Ui::MainWindow)
            {
            ui->setupUi(this);

            QString ChessPieces[12];
            
            ChessPieces[0] = "C:/Users/User/Desktop/WhitePawn.jpg";
            ChessPieces[1] = "C:/Users/User/Desktop/WhiteRook.jpg";
            ChessPieces[2] = "C:/Users/User/Desktop/WhiteKnight.jpg";
            ChessPieces[3] = "C:/Users/User/Desktop/WhiteBishop.jpg";
            ChessPieces[4] = "C:/Users/User/Desktop/WhiteQueen.jpg";
            ChessPieces[5] = "C:/Users/User/Desktop/WhiteKing.jpg";
            ChessPieces[6] = "C:/Users/User/Desktop/BlackPawn.jpg";
            ChessPieces[7] = "C:/Users/User/Desktop/BlackRook.jpg";
            ChessPieces[8] = "C:/Users/User/Desktop/BlackKnight.jpg";
            ChessPieces[9] = "C:/Users/User/Desktop/BlackBishop.jpg";
            ChessPieces[10] = "C:/Users/User/Desktop/BlackQueen.jpg";
            ChessPieces[11] = "C:/Users/User/Desktop/BlackKing.jpg";
            
            
            
            QPainter * ChessPiece = new QPainter();
            QImage * Image = new QImage("C:/Users/User/Desktop/WhiteQueen.jpg");
            //Image->
            
            QRect Source;
            QRect Dest;
            
            Source.setCoords(0,0,30,30);
            Dest.setCoords(100,100,200,200);
            
            QPainter *Painter = new QPainter();
            Painter->drawImage(Dest,*Image,Source);
            
            //const QPixmap Pixmap;
            
            //ChessPiece->drawImage(Dest,Image,Source);
            

            // ChessPiece->drawPixmap(0,0,30,30,Pixmap);

            }

            MainWindow::~MainWindow()
            {
            delete ui;
            }

            The chess piece is not drawn for some reason ?

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

              Hi,

              How do you determine they are not drawn ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • Q Offline
                Q Offline
                Quantum1982
                wrote on last edited by
                #9

                I mean that the chess piece is not showing on the screen ?

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #10

                  The code you posted does not include anything that would bring the QImage on screen.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • Q Offline
                    Q Offline
                    Quantum1982
                    wrote on last edited by
                    #11

                    @Quantum1982 said in Raspbian 2 player chess game:

                    Painter->drawImage(Dest,*Image,Source);

                    But what about the line :

                    Painter->drawImage(Dest,*Image,Source); ?

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #12

                      That painter does in fact not paint on anything.

                      Please re-read the class documentation.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • Q Offline
                        Q Offline
                        Quantum1982
                        wrote on last edited by
                        #13

                        Ok

                        I changed it to this :

                        #include "mainwindow.h"
                        #include "ui_mainwindow.h"
                        #include <QPainter>
                        #include <QImage>
                        #include <QRectF>

                        MainWindow::MainWindow(QWidget *parent)
                        : QMainWindow(parent)
                        , ui(new Ui::MainWindow)
                        {
                        ui->setupUi(this);

                        QRectF target(10.0,10.0,50.0,50.0);
                        QRectF source(0.0,0.0,50.0,50.0);
                        
                        // QImage Image("C:/Users/User/Desktop/WhiteQueen.jpg");
                        
                        QPixmap Pixmap("C:/Users/User/Desktop/WhiteQueen.jpg");
                        QPainter Painter;
                        
                        Painter.drawPixmap(target,Pixmap,source);
                        

                        }

                        MainWindow::~MainWindow()
                        {
                        delete ui;
                        }

                        Still no chess piece on the screen ?

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #14

                          Because you are still using QPainter incorrectly. A bit less than before but still incorrectly.

                          You should paint what you want on a QPixmap that you will set on a QLabel if you want to show it.

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          1
                          • Q Offline
                            Q Offline
                            Quantum1982
                            wrote on last edited by
                            #15

                            Ok, but now I am getting this error

                            C:\Users\User\Documents\Chess\main.cpp:-1: error: C1041: cannot open program database 'C:\Users\User\Documents\build-Chess-Desktop_Qt_5_12_12_MSVC2015_64bit-Debug\debug\Chess.vc.pdb'; if multiple CL.EXE write to the same .PDB file, please use /FS

                            1 Reply Last reply
                            0
                            • Q Offline
                              Q Offline
                              Quantum1982
                              wrote on last edited by
                              #16

                              Ok I fixed it.

                              Now I am trying this :

                              #include "mainwindow.h"
                              #include "ui_mainwindow.h"

                              #include <QImage>
                              #include <QLabel>

                              MainWindow::MainWindow(QWidget *parent)
                              : QMainWindow(parent)
                              , ui(new Ui::MainWindow)
                              {
                              ui->setupUi(this);

                              QPixmap Pixmap("C:/Users/User/Desktop/WhiteQueen.jpg");
                              QLabel WhiteQueen;
                              WhiteQueen.setGeometry(50,50,100,100);
                              WhiteQueen.setPixmap(Pixmap);
                              

                              }

                              MainWindow::~MainWindow()
                              {
                              delete ui;
                              }

                              Still nothing appears ?

                              JonBJ 1 Reply Last reply
                              0
                              • Q Quantum1982

                                Ok I fixed it.

                                Now I am trying this :

                                #include "mainwindow.h"
                                #include "ui_mainwindow.h"

                                #include <QImage>
                                #include <QLabel>

                                MainWindow::MainWindow(QWidget *parent)
                                : QMainWindow(parent)
                                , ui(new Ui::MainWindow)
                                {
                                ui->setupUi(this);

                                QPixmap Pixmap("C:/Users/User/Desktop/WhiteQueen.jpg");
                                QLabel WhiteQueen;
                                WhiteQueen.setGeometry(50,50,100,100);
                                WhiteQueen.setPixmap(Pixmap);
                                

                                }

                                MainWindow::~MainWindow()
                                {
                                delete ui;
                                }

                                Still nothing appears ?

                                JonBJ Offline
                                JonBJ Offline
                                JonB
                                wrote on last edited by JonB
                                #17

                                @Quantum1982
                                QLabel WhiteQueen; is a local variable. It goes out of scope at the end of the constructor. And you never added the QLabel to the MainWindow anyway.

                                I would take some time to look at some basic Qt widgets examples.

                                1 Reply Last reply
                                1
                                • Q Offline
                                  Q Offline
                                  Quantum1982
                                  wrote on last edited by
                                  #18

                                  Ok, so where should I declare the label then for it to be drawn ?

                                  JonBJ 1 Reply Last reply
                                  0
                                  • Q Quantum1982

                                    Ok, so where should I declare the label then for it to be drawn ?

                                    JonBJ Offline
                                    JonBJ Offline
                                    JonB
                                    wrote on last edited by JonB
                                    #19

                                    @Quantum1982
                                    This is not a longterm design plan. But from where you are now:

                                    • Move the variable out to be a member of the MainWindow class.
                                    • Change it to be a pointer.
                                    • Set it to a newed instance back in the constructor, with the MainWindow as its parent: WhiteQueen = new QLabel(this).

                                    At least you should then be able to see it.

                                    I'm not sure I would do this whole chess UI with widgets, probably a graphics scene with QGraphicsPixmapItems instead, but that's a whole different matter.

                                    1 Reply Last reply
                                    1
                                    • Q Offline
                                      Q Offline
                                      Quantum1982
                                      wrote on last edited by
                                      #20

                                      I am not sure how to do that.
                                      This is what I have so far :
                                      #include "mainwindow.h"
                                      #include "ui_mainwindow.h"

                                      #include <QImage>
                                      #include <QLabel>

                                      MainWindow::MainWindow(QWidget *parent)
                                      : QMainWindow(parent)
                                      , ui(new Ui::MainWindow)
                                      {
                                      ui->setupUi(this);

                                      QString ChessPieces[12];
                                      
                                      ChessPieces[0] = "C:/Users/User/Desktop/WhitePawn.jpg";
                                      ChessPieces[1] = "C:/Users/User/Desktop/WhiteRook.jpg";
                                      ChessPieces[2] = "C:/Users/User/Desktop/WhiteKnight.jpg";
                                      ChessPieces[3] = "C:/Users/User/Desktop/WhiteBishop.jpg";
                                      ChessPieces[4] = "C:/Users/User/Desktop/WhiteQueen.jpg";
                                      ChessPieces[5] = "C:/Users/User/Desktop/WhiteKing.jpg";
                                      ChessPieces[6] = "C:/Users/User/Desktop/BlackPawn.jpg";
                                      ChessPieces[7] = "C:/Users/User/Desktop/BlackRook.jpg";
                                      ChessPieces[8] = "C:/Users/User/Desktop/BlackKnight.jpg";
                                      ChessPieces[9] = "C:/Users/User/Desktop/BlackBishop.jpg";
                                      ChessPieces[10] = "C:/Users/User/Desktop/BlackQueen.jpg";
                                      ChessPieces[11] = "C:/Users/User/Desktop/BlackKing.jpg";
                                      
                                      QPixmap Pixmap("C:/Users/User/Desktop/WhiteQueen.jpg");
                                      WhiteQueen.setGeometry(50,50,100,100);
                                      WhiteQueen.setPixmap(Pixmap);
                                      

                                      }

                                      MainWindow::~MainWindow()
                                      {
                                      delete ui;
                                      }
                                      #ifndef MAINWINDOW_H
                                      #define MAINWINDOW_H

                                      #include <QMainWindow>
                                      #include <QLabel>

                                      QT_BEGIN_NAMESPACE
                                      namespace Ui { class MainWindow; }
                                      QT_END_NAMESPACE

                                      class MainWindow : public QMainWindow
                                      {
                                      Q_OBJECT

                                      public:
                                      QLabel WhiteQueen;
                                      MainWindow(QWidget *parent = nullptr);
                                      ~MainWindow();

                                      private:
                                      Ui::MainWindow *ui;
                                      };
                                      #endif // MAINWINDOW_H

                                      Then there is still no chess piece displayed ?

                                      JonBJ 1 Reply Last reply
                                      0
                                      • Q Quantum1982

                                        I am not sure how to do that.
                                        This is what I have so far :
                                        #include "mainwindow.h"
                                        #include "ui_mainwindow.h"

                                        #include <QImage>
                                        #include <QLabel>

                                        MainWindow::MainWindow(QWidget *parent)
                                        : QMainWindow(parent)
                                        , ui(new Ui::MainWindow)
                                        {
                                        ui->setupUi(this);

                                        QString ChessPieces[12];
                                        
                                        ChessPieces[0] = "C:/Users/User/Desktop/WhitePawn.jpg";
                                        ChessPieces[1] = "C:/Users/User/Desktop/WhiteRook.jpg";
                                        ChessPieces[2] = "C:/Users/User/Desktop/WhiteKnight.jpg";
                                        ChessPieces[3] = "C:/Users/User/Desktop/WhiteBishop.jpg";
                                        ChessPieces[4] = "C:/Users/User/Desktop/WhiteQueen.jpg";
                                        ChessPieces[5] = "C:/Users/User/Desktop/WhiteKing.jpg";
                                        ChessPieces[6] = "C:/Users/User/Desktop/BlackPawn.jpg";
                                        ChessPieces[7] = "C:/Users/User/Desktop/BlackRook.jpg";
                                        ChessPieces[8] = "C:/Users/User/Desktop/BlackKnight.jpg";
                                        ChessPieces[9] = "C:/Users/User/Desktop/BlackBishop.jpg";
                                        ChessPieces[10] = "C:/Users/User/Desktop/BlackQueen.jpg";
                                        ChessPieces[11] = "C:/Users/User/Desktop/BlackKing.jpg";
                                        
                                        QPixmap Pixmap("C:/Users/User/Desktop/WhiteQueen.jpg");
                                        WhiteQueen.setGeometry(50,50,100,100);
                                        WhiteQueen.setPixmap(Pixmap);
                                        

                                        }

                                        MainWindow::~MainWindow()
                                        {
                                        delete ui;
                                        }
                                        #ifndef MAINWINDOW_H
                                        #define MAINWINDOW_H

                                        #include <QMainWindow>
                                        #include <QLabel>

                                        QT_BEGIN_NAMESPACE
                                        namespace Ui { class MainWindow; }
                                        QT_END_NAMESPACE

                                        class MainWindow : public QMainWindow
                                        {
                                        Q_OBJECT

                                        public:
                                        QLabel WhiteQueen;
                                        MainWindow(QWidget *parent = nullptr);
                                        ~MainWindow();

                                        private:
                                        Ui::MainWindow *ui;
                                        };
                                        #endif // MAINWINDOW_H

                                        Then there is still no chess piece displayed ?

                                        JonBJ Offline
                                        JonBJ Offline
                                        JonB
                                        wrote on last edited by
                                        #21

                                        @Quantum1982
                                        You still have not added your WhiteQueen onto your main window. I suggested code which will do this.

                                        1 Reply Last reply
                                        0
                                        • Q Offline
                                          Q Offline
                                          Quantum1982
                                          wrote on last edited by
                                          #22

                                          I want to add the pieces programmatically. I don't want to drag and drop labels onto the form. These pieces are going to be stored inside an array which will be loaded dynamically.

                                          JonBJ 2 Replies 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