【问题标题】:Qt simple text editor, what's wrong?Qt简单的文本编辑器,怎么了?
【发布时间】:2015-01-12 10:29:09
【问题描述】:

我正在使用他们的文本编辑器 tutorial 学习 Qt 基础知识。

我无法弄清楚我在 main() 中的代码有什么问题。我遇到以下错误:

链接器命令失败,退出代码为 1(使用 -v 查看调用)

未找到架构 x86_64 的符号

这是我的代码:

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();
}

【问题讨论】:

  • 当您应该链接到 64 位库时,您正在尝试链接到 32 位库。
  • 您尝试在什么环境中构建它?
  • @LahiruChandima 我正在使用 QtCreator。 MacBook Air OSX 优胜美地 10.10.1.
  • 检查底部的编译器输出窗格中是否有任何链接器错误

标签: c++ qt


【解决方案1】:

在源文件的底部添加以下内容。

#include "main.moc"

然后执行build->run qmake,然后执行build->rebuild

【讨论】:

    猜你喜欢
    • 2012-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-24
    • 2012-08-13
    • 1970-01-01
    • 2020-05-19
    相关资源
    最近更新 更多