We help IT Professionals succeed at work.
Get Started

General message class in trouble with const function

Ingo Förster
on
78 Views
Last Modified: 2020-01-26
In my QT app I have a global class to show error messages.  This is working well in common functions.

int32 MdiChildHex::startHex(QString strBurnDrive)
{
    int32 ret = ::SetBurnDevice(strBurnDrive.at(0).toLatin1());
    if(showDiskbutlerMessage(ret, this)==false) {
        thisSuccessfullCreated = false;
        return;
    }
}

Open in new window


But if the function will hold a "const" in it, the function is not recognized-

int32 MdiChildHex::ReadSector(int32 sectorIndex) const
{
    char *buf = new char[2352];
    QByteArray mdata;

    int32 ret = ::ReadSectors(BS_CURRENT_DEVICE, sectorIndex, 1, BS_IMG_ISO, buf, bufferSize);
    showDiskbutlerMessage(ret, this);

    QByteArray byteArray = QByteArray::fromRawData(buf, bufferSize);

    hexView->clear();

    hexView->setData(new QHexView::DataStorageArray(byteArray));

    return ret;
}

Open in new window


The message I see in QTCreator is:
mdichild_hex.cpp:116:5: error: no matching function for call to 'showDiskbutlerMessage'
messanger.h:7:6: note: candidate function not viable: no known conversion from 'const MdiChildHex *' to 'QWidget *' for 2nd argument

message.h
#ifndef MESSANGER_H
#define MESSANGER_H

#include <QtWidgets>
#include "FoxSDKExport.h"

bool showDiskbutlerMessage(int32 nError, QWidget* parent);

#endif // MESSANGER_H

Open in new window


message.cpp
#include "messanger.h"
#include "utils_common.h"
#include <QMessageBox>


bool showDiskbutlerMessage(int32 nError, QWidget* parent){

    if (nError != BS_SDK_ERROR_NO){

        TCHAR chError[2048];
        int32 nLength = 2048;

        ::GetText(nError,chError, &nLength);

        QString errDesc;
#if defined (WIN32)
        errDesc= QString::fromUtf16(chError);
#else
        errDesc= QString::fromUtf8(chError);
#endif

        QMessageBox::information(getMainWindow(),  QWidget::tr("Diskbutler Error"),
                                  errDesc);
        return false;
    }

    return true;
}

Open in new window


What is the secret here with const?
Comment
Watch Question
This question hasn't been answered yet.
While you wait, find out how you can maximize your capability with the most trusted tool in IT.
Explore More Ask a Question
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE