Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

comparison between QAbstractButton and QPushButton* lacks a cast

Tags:

c++

android

gcc

qt

My code appears below. When I try to compile this, I get:

error: 29:38 comparison between distinct pointer types QAbstractButton and QPushButton* lacks a cast -> 'if (stdmetBox.clickedButton() == stdButton)'

System: Amazon Kindle Fire 7" running Cyanogenmod 11.0 (Android 4.4.2 Kitkat) Compiler: G++/GCC (GCC for C4droid plugin version 4.9.1) IDE: C4droid with SDL, GCC, and Ministro plugins

Any help would be greatly appreciated. I've searched but the only instance I can find is iOS specific.

#include <fstream>
#include <QApplication>
#include <QLabel>
#include <QMessageBox>
#include <QString>
#include <QAbstractButton>
#include <QInputDialog>
#include <QDebug>

using namespace std;

int setup() 
{
    string unitchar;
    string unitcharo;
    bool setupSuccess;
    int returncode;
    QMessageBox msgBox;
    QMessageBox stdmetBox;
    QMessageBox ynBox;

    msgBox.setText("Welcome to Tyler's Fitness App! This app will help you with your fitness goals, whatever they may be. Let's get you set up!");
    msgBox.exec();

    QPushButton *stdButton = stdmetBox.addButton(QT_TR_NOOP("Standard"), QMessageBox::ActionRole);
    QPushButton *metButton = stdmetBox.addButton(QT_TR_NOOP("Metric"), QMessageBox::ActionRole);                                                
    stdmetBox.exec();

    if (stdmetBox.clickedButton() == stdButton)
    {
        unitchar = "standard";
        unitcharo = "metric";
    }
    else if (stdmetBox.clickedButton() == metButton)
    {
        unitchar = "metric";
        unitcharo = "standard";
    }
    else
    {
        setupSuccess = false;
        returncode = 0;
        return returncode; 
    }

    if (unitchar == "standard")
    {
        ynBox.setInformativeText("Standard units include feet, miles, mph, pounds, etc.");
    }
    else 
    {
        ynBox.setInformativeText("Metric units include meters, kilometers, kph, kilograms, etc.");
    } 

    QPushButton *yesButton = ynBox.addButton(QT_TR_NOOP("Yes"), QMessageBox::ActionRole);
    QPushButton *noButton = ynBox.addButton(QT_TR_NOOP("No"), QMessageBox::ActionRole);
    ynBox.setText("Is that okay?")
    while (ynBox.clickedButton() == noButton)
    {
        if (unitchar == "standard")
        {
            unitchar = "metric";
            unitcharo = "standard";
        }
        else 
        {
            unitchar = "standard";
            unitcharo = "metric";
        }
        if (unitchar == "standard")
        {
            ynBox.setInformativeText("Standard units include feet, miles, mph, pounds, etc.");
        }
        else 
        {
            ynBox.setInformativeText("Metric units include meters, kilometers, kph, kilograms, etc.");
        }
        result = ynBox.exec();
    }

    if (unitchar == "standard")
    {
        msgBox.setText("Great! You've selected standard units.");
        msgBox.exec();
        setupSuccess = true;

    }
    else 
    {
        msgBox.setText("Great! You've selected metric units.");
        msgBox.exec();
        setupSuccess = true;
    }

    if (setupSuccess != true)
    {
        returncode = 0;
    }
    else if (unitchar == "standard")
    {
        returncode = 1;
    }
    else
    {
        returncode = 2;
    }
    return returncode;                      
}                       

int main(int argc, char* argv[])
{ 
    QApplication app(argc, argv);  
    unitmaster = setup();
    if ((unitmaster == 1) || (unitmaster == 2))
    {
        QMessageBox successBox;
        successBox.setText("The program has completed successfully!");
        successBox.exec();
    }
    else 
    {
        QMessageBox errorBox;
        errorBox.setText("The program has completed successfully!");
        errorBox.exec();
    }            
    return app.exec();
}
like image 782
Tyler Lewis Avatar asked Apr 15 '15 11:04

Tyler Lewis


1 Answers

You seem to have forgotten to include <QPushButton> even though you use QPushButton in a way that requires it's definition. One of the headers must have declared it because it's recognized as a type, but if it is incomplete, then the compiler wouldn't know that QPushButton* is convertible to QAbstractButton*.

As a general rule, always include the headers that define the types that you use, unless you're sure that a declaration is enough. Implicit conversions to base pointer are a thing that require the definition.

like image 105
eerorika Avatar answered Nov 11 '22 05:11

eerorika