PDA

View Full Version : error C3861: 'tr': identifier not found, even with argument-dependent lookup



Mars
27th February 2006, 03:18
Visual studio 2003 with QT 4 on windows xp professional, compiling the following code fail with message:
main.cpp(33) : error C3861: 'tr': identifier not found, even with argument-dependent lookup

my code:
#include <QApplication>
#include <QFont>
#include <QPushButton>
#include <QWidget>

class MyWidget : public QWidget
{
public:
MyWidget(QWidget *parent = 0);
};

MyWidget::MyWidget(QWidget *parent) :
QWidget(parent)
{
setFixedSize(200, 120);

QPushButton *quit = new QPushButton(QObject::tr("Quit"), this);
quit->setGeometry(62, 40, 75, 30);
quit->setFont(QFont("Times", 18, QFont::Bold));

connect(quit, SIGNAL(clicked()), qApp, SLOT(quit()));
}

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

QWidget Window;
Window.resize(640, 480);

QPushButton btnExit;
btnExit.setParent(&Window);
btnExit.setText(tr("Exit"));
btnExit.setGeometry(100, 100, 125, 25);
btnExit.setFont(QFont("Fixedsys", 12, QFont::Bold, true));
QObject::connect(&btnExit, SIGNAL(clicked()), &Application, SLOT(quit()));
Window.show();

return Application.exec();
}


anybody help me?thx.

jpn
27th February 2006, 05:21
Use a static method QObject::tr() or QCoreApplication::translate() on line 33.

PS. Use code blocks around your code to make it more readable.

Mars
27th February 2006, 05:33
Use a static method QObject::tr() or QCoreApplication::translate() on line 33.

PS. Use code blocks around your code to make it more readable.

Thanks but it is not working, the compiler report the same message.


QPushButton *quit = new QPushButton(QObject::tr("Quit"), this);

jpn
27th February 2006, 05:51
Line 33 is

btnExit.setText(tr("Exit"));