简体   繁体   English

Qt简单文本编辑器,怎么了?

[英]Qt simple text editor, what's wrong?

I'm learning Qt basics using their text editor tutorial . 我正在使用他们的文本编辑器教程来学习Qt基础知识。

I can't figure out what's wrong with my code in main(). 我无法弄清楚main()中的代码出了什么问题。 I'm having the following errors: 我遇到以下错误:

linker command failed with exit code 1 (use -v to see invocation) 链接器命令失败,退出代码为1(使用-v查看调用)

symbol(s) not found for architecture x86_64 找不到架构x86_64的符号

Here's my code: 这是我的代码:

class TextEditor : public QWidget
{
    Q_OBJECT

public:
    TextEditor();

private slots:
    void quit();

private:
    QTextEdit *textEdit;
    QPushButton *quitButton;
};

TextEditor::TextEditor()
{
    textEdit = new QTextEdit;
    quitButton = new QPushButton(tr("Quit"));

    connect(quitButton, SIGNAL(clicked()), this, SLOT(quit()));

    QVBoxLayout *layout = new QVBoxLayout;
    layout->addWidget(textEdit);
    layout->addWidget(quitButton);

    setLayout(layout);

    setWindowTitle(tr("TextEditor"));
}

void TextEditor::quit()
{
    QMessageBox messageBox;
    messageBox.setWindowTitle(tr("TextEditor"));
    messageBox.setText(tr("Really?"));
    messageBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
    messageBox.setDefaultButton(QMessageBox::No);
    if (messageBox.exec() == QMessageBox::Yes)
        qApp->quit();
}

int main (int argc, char *argv[])
{
    QApplication app(argc, argv);

    TextEditor w;
    w.show();

    return app.exec();
}

add following to the bottom of the source file. 在源文件的底部添加以下内容。

#include "main.moc"

Then do build->run qmake and then build->rebuild 然后执行build->run qmake ,然后执行build->rebuild

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM