• Najnowsze pytania
  • Bez odpowiedzi
  • Zadaj pytanie
  • Kategorie
  • Tagi
  • Zdobyte punkty
  • Ekipa ninja
  • IRC
  • FAQ
  • Regulamin
  • Książki warte uwagi

Messagebox w Qt

0 głosów
349 wizyt
pytanie zadane 24 kwietnia 2019 w C i C++ przez JuniorPL Użytkownik (770 p.)

Cześć mam problem z wyświetleniem okna informacji. Dodałem bibliotekę QMessageBox ale w miejscu wywołanie otrzymuję błąd informujący o braku dopasowanie funkcji wywołania. Może ktoś spotkał się z taką sytuacją.

#include "Bullet.h"
#include <QTimer>
#include <QGraphicsScene>
#include <QDebug>
#include <QGraphicsRectItem>
#include <QtMath>
#include <QMessageBox>
 Bullet::Bullet(QGraphicsItem *parent): QObject(), QGraphicsPixmapItem(parent)
 {

    // draw graphics
    setPixmap(QPixmap(":/img/pocisk.png"));

    // connect
    QTimer *timer = new QTimer();
    connect(timer,SIGNAL(timeout()),this,SLOT(move()));

    timer->start(10);
}

  int Bullet::move(){
      double a,b,c,p;
      p=qFabs(angle)*30;
      int yPosition;
   
      if(player == "playerOne")
      {
    //right shot
          p=1250-p;
          a=1600/((-1400 + p)*(-1400 + p));
          b=-((1600*(1400 + p))/((-1400 + p)*(-1400 + p)));
          c=(700*(1960000 + 400*p + p*p))/((-1400 + p)*(-1400 + p));

         yPosition =((a*x()*x()+b*x()+c));
         setPos(x()-5,yPosition);
      }
      //left shot
      else {
         a=(1600/((100 + p)*(100+p)));
         b=-((1600*(-100 + p))/((100 + p)*(100+p)));
         c=((100*(70000 - 200*p + 7*p*p))/((100 + p)*(100+p)));
         yPosition = ((a*x()*x()+b*x()+c));

          setPos(x()+5,yPosition);
      }

   if(pos().y()>800)
   {
    scene()->removeItem(this);
    delete this;
    QMessageBox::information(this,"Gratulation","Win...");//error
   return 1;
   }
   else
   {
       return 0;
   }
}

 

komentarz 24 kwietnia 2019 przez niezalogowany
Przed użyciem QMessageBox usuwasz rodzica (this) dla metody information. Nie o to chodzi?
komentarz 24 kwietnia 2019 przez JuniorPL Użytkownik (770 p.)

Taka zmiana nie wpywa na zmianę komunikatu błędu.

 QMessageBox::information("Gratulation","Win...");

 

komentarz 24 kwietnia 2019 przez JuniorPL Użytkownik (770 p.)
Super dzięki, faktycznie nie zwróciłem uwagi na to że wcześniej usuwam ten element.

2 odpowiedzi

0 głosów
odpowiedź 24 kwietnia 2019 przez DeBos123 Nałogowiec (44,950 p.)

Spróbuj dodać QMessageBox::Ok do argumentów.

komentarz 24 kwietnia 2019 przez JuniorPL Użytkownik (770 p.)
Tutaj chyba chodzi o ten this ponieważ on nie może zmienić obieku klasy Bullet na na QWisget.
komentarz 24 kwietnia 2019 przez DeBos123 Nałogowiec (44,950 p.)

Z dokumentacji:

QMessageBox::information(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton = NoButton)

Spróbuj zamienić this na nullptr, reszta powinna być ok.

0 głosów
odpowiedź 24 kwietnia 2019 przez Bondrusiek Maniak (61,440 p.)

Witam,

funkcja QMessageBox::information() przyjmuje więcej argumentów : https://doc.qt.io/qt-5/qmessagebox.html#StandardButton-enum

Przykładowe wartości:

QMessageBox::Ok 0x00000400 An "OK" button defined with the AcceptRole.
QMessageBox::Open 0x00002000 An "Open" button defined with the AcceptRole.
QMessageBox::Save 0x00000800 A "Save" button defined with the AcceptRole.
QMessageBox::Cancel 0x00400000 A "Cancel" button defined with the RejectRole.
QMessageBox::Close 0x00200000 A "Close" button defined with the RejectRole.
QMessageBox::Discard 0x00800000 A "Discard" or "Don't Save" button, depending on the platform, defined with the DestructiveRole.
QMessageBox::Apply 0x02000000 An "Apply" button defined with the ApplyRole.
QMessageBox::Reset 0x04000000 A "Reset" button defined with the ResetRole.
QMessageBox::RestoreDefaults 0x08000000 A "Restore Defaults" button defined with the ResetRole.
QMessageBox::Help 0x01000000 A "Help" button defined with the HelpRole.
QMessageBox::SaveAll 0x00001000 A "Save All" button defined with the AcceptRole.
QMessageBox::Yes 0x00004000 A "Yes" button defined with the YesRole.
QMessageBox::YesToAll 0x00008000 A "Yes to All" button defined with the YesRole.
QMessageBox::No 0x00010000 A "No" button defined with the NoRole.
QMessageBox::NoToAll 0x00020000 A "No to All" button defined with the NoRole.
QMessageBox::Abort 0x00040000 An "Abort" button defined with the RejectRole.
QMessageBox::Retry 0x00080000 A "Retry" button defined with the AcceptRole.
QMessageBox::Ignore 0x00100000 An "Ignore" button defined with the AcceptRole.
QMessageBox::NoButton 0x00000000 An invalid button.

 Co do kodu to mam jeszcze taką wątpliwość. Usuwasz element następnie odnosisz się do tego obiektu:

    delete this;
    QMessageBox::information(this,"Gratulation","Win...");
///// zamien na np
    delete this;
    QMessageBox::information(0,"Gratulation","Win...", QMessageBox::Ok);

 

Podobne pytania

0 głosów
1 odpowiedź 298 wizyt
+1 głos
0 odpowiedzi 235 wizyt
0 głosów
1 odpowiedź 379 wizyt
pytanie zadane 20 września 2021 w C i C++ przez tonn204 Mądrala (7,470 p.)

93,765 zapytań

142,721 odpowiedzi

323,373 komentarzy

63,359 pasjonatów

Motyw:

Akcja Pajacyk

Pajacyk od wielu lat dożywia dzieci. Pomóż klikając w zielony brzuszek na stronie. Dziękujemy! ♡

Oto polecana książka warta uwagi.
Pełną listę książek znajdziesz tutaj

Twierdza Linux. Bezpieczeństwo dla dociekliwych

Aby uzyskać rabat -10%, użyjcie kodu pasja-linux, wpisując go w specjalne pole w koszyku.

...