QWidget에서 상속받은 MyWindow라는 클래스를 만들어 창을 만들었습니다.Qt의 슬롯에 인수 넣기
class MyWindow: public QWidget{
public:
MyWindow(QString title,QString icon,int w = 600,int h = 400);
int getWidth() const;
int getHeight() const;
public slots:
void openDialogBox(QString title,QString message);
private:
int m_width;
int m_height;
};
는 제목과 인수로 대화 상자의 메시지를 소요 openDialogBox 슬롯이 있습니다 : 여기 mywindow.h의 내용이다. 나는 슬롯 &MyWindow::openDialogBox
에 인수를 보내려고, 마지막 줄에
MyWindow myWindow("Example window",QCoreApplication::applicationDirPath() + "/icon.png");
QMenuBar menuBar(&myWindow);
menuBar.setGeometry(0,0,myWindow.getWidth(),menuBar.geometry().height());
QMenu *fileMenu = new QMenu("&File");
QAction *fileMenu_open = fileMenu->addAction("&Open");
MyWindow::connect(fileMenu_open,&QAction::triggered,&myWindow,&MyWindow::openDialogBox);
것 :
나는 기본적으로 다음과 같습니다 메뉴 표시 줄을했습니다. (나는 이미 이유를 알고, 그것이 작동하지 않은 이유를 설명 할 필요가 없습니다)
MyWindow::connect(fileMenu_open,&QAction::triggered,&myWindow,&MyWindow::openDialogBox("Title","Hello, this is a message"));
했지만 작동하지 않았다 : 내가 할 노력했다. 제대로 작동하려면 어떻게해야합니까?
* QWeakPointer 개체는 QSharedPointer. *에서 할당하여 만들 수 있습니다. [here] (https://doc.qt.io/qt-5/qweakpointer.html#details)를 참조하십시오. 'myWindow'는'QSharedPointer'가 아닙니다. – Mike
'myWindow'가 복사 또는 이동되는 것에 대해 걱정이된다면,'QObject' [can not] (https://doc.qt.io/qt-5/qobject.html#no-copy-constructor-or- 할당 연산자)가 복사됩니다. 'myWindow'가 매달려있는 포인터 (파괴 된 경우)에 대해 걱정된다면,'context' 객체가 파괴되면 연결은 자동으로 끊어집니다. [here] (https://doc.qt.io/qt)를보십시오. -5/qobject.html # connect-5), 응답의 컨텍스트 오브젝트는'& myWindow'입니다. 나는 여기에'QWeakPointer'를 사용하려하지 않습니다. – Mike
그래, 나는 QPointer를 의미했다. 그리고 귀하의 링크는 QObject를 이동하지 않고 복사 할 수 없다고 말합니다. –