Google에서이 답변을 찾으려고했지만 열매 맺은 것은 없습니다. Qt4에서 Qt5로 앱을 변환하는 중입니다. 이 응용 프로그램은 Qt4에서 완벽하게 컴파일되었지만 지금 Qt5와 컴파일하려고하면이 권한 오류가 발생합니다. 이 클래스의 상태는 두 버전 모두에서 보호되어 있으므로 변경할 필요가있는 사항을 이해하는 데 어려움을 겪고 있습니다.'virtual bool QAbstractScrollArea :: eventFilter (QObject *, QEvent *)'가 보호되어 있습니다.
이 컴파일 문제는 몇 가지 다른 우분투 설치 (wsl 포함)에서 복제되었지만 아직 Fedora에서 시도하지 않았습니다.
다음은 클래스의 하위 집합
#include <QWidget>
#include <QEvent>
#include <QTableWidget>
#include <QItemDelegate>
#include <QModelIndex>
#include <QSize>
#include <qdialog.h>
#include <qcombobox.h>
#include "ui_pegs_page.h"
#include <string>
class EGS_ConfigReader;
class QProcess;
class PEGS_RunOutput;
class QTableWidget;
struct Element {
int Z;
std::string symbol;
float aw;
float Iev;
float rho;
};
const int n_element = 100;
extern Element element_data[];
class TableEventHandler : public QObject {
Q_OBJECT
public:
TableEventHandler(QTableWidget *parent);
protected:
bool eventFilter(QObject *o, QEvent *e);
private:
QStringList itemCopy;
QList<QTableWidgetSelectionRange> copyRange;
};
편집 :
가 여기에 문제가있는 방법이다.
TableEventHandler::TableEventHandler(QTableWidget *parent) :
QObject(parent) {
if(parent == 0)
qFatal("TableEventHandler::TableEventHandler: parent can not be null!");
}
bool TableEventHandler::eventFilter(QObject *o, QEvent *e) {
if(!o) qWarning("TableEventHandler::eventFilter called with 0 object?");
if(QString(o->metaObject()->className()) != tr("QTableWidget")) {
#ifdef EI_DEBUG
qDebug("Only QTableWidget objects accepted! Returning!");
#endif
return false;
}
QTableWidget *to = (QTableWidget *)o;
if(e->type() == QEvent::KeyPress) {
QKeyEvent *ke = (QKeyEvent*)e;
if(ke->matches(QKeySequence::Copy)){
QString cellText; itemCopy.clear(); copyRange.clear();
QList<QTableWidgetSelectionRange> ts = to->selectedRanges();
if(!ts.isEmpty()) {
for (int irow = ts.first().topRow(); irow <= ts.first().bottomRow(); irow++){
for (int icol = ts.first().leftColumn(); icol <= ts.first().rightColumn(); icol++){
QTableWidgetItem *w = to->item(irow,icol);
if(w) cellText = w->text();
if (!cellText.isEmpty()){
itemCopy << cellText;
}
else
itemCopy << " ";
}
}
copyRange = ts;
//cout << itemCopy.join(", ").toLatin1().data() << endl;
}
else {
QTableWidgetItem *w = to->item(to->currentRow(), to->currentColumn());
if (w) cellText = w->text();
if (!cellText.isEmpty())
itemCopy << cellText;
else itemCopy << "";
}
return true;
}
else if(ke->matches(QKeySequence::Paste) && !itemCopy.isEmpty() && !copyRange.isEmpty()){
QList<QTableWidgetSelectionRange> cs = to->selectedRanges();
int top = cs.first().topRow(), left = cs.first().leftColumn(), icount = 0;
QTableWidgetSelectionRange ts = QTableWidgetSelectionRange(
top , left,
top + copyRange.first().rowCount()-1,
left + copyRange.first().columnCount()-1);
for (int irow = ts.topRow(); irow <= ts.bottomRow(); irow++){
for (int icol = ts.leftColumn(); icol <= ts.rightColumn(); icol++){
if (++icount <= itemCopy.size())
to->setItem(irow, icol, new QTableWidgetItem(itemCopy[icount-1]));
to->setItem(irow, icol, new QTableWidgetItem(itemCopy[icount-1]));
}
}
return true;
}
else if(ke->matches(QKeySequence::Cut)){
QString cellText; itemCopy.clear(); copyRange.clear();
QList<QTableWidgetSelectionRange> ts = to->selectedRanges();
if(!ts.isEmpty()) {
for (int irow = ts.first().topRow(); irow <= ts.first().bottomRow(); irow++) {
for(int icol = ts.first().leftColumn(); icol <= ts.first().rightColumn(); icol++) {
QTableWidgetItem *w = to->item(irow,icol);
if(w) cellText = w->text();
if (!cellText.isEmpty()){
itemCopy << cellText;
}
else
itemCopy << "";
to->setItem(irow,icol,0);
}
}
copyRange = ts;
//cout << itemCopy.join(", ").toLatin1().data() << endl;
}
return true;
}
else if(ke->matches(QKeySequence::Delete)){
QList<QTableWidgetSelectionRange> ts = to->selectedRanges();
if(!ts.isEmpty()) {
for (int irow = ts.first().topRow(); irow <= ts.first().bottomRow(); irow++) {
for(int icol = ts.first().leftColumn(); icol <= ts.first().rightColumn(); icol++) {
to->setItem(irow,icol,0);
}
}
}
return true;
}
else
to->eventFilter(o, e);
}
return false;
}
나는 당신이 어디로 가고 있는지 살펴보고 탐색 할 것입니다. 나는 그것이 어떻게 상속 문제라면 이것이 qt4에 나오지 않았는지 궁금하다. – crcrewso