• 7589阅读
  • 2回复

error: ‘setWindowTitle’ was not declared in this scope [复制链接]

上一主题 下一主题
离线e3399
 

只看楼主 倒序阅读 楼主  发表于: 2010-12-31
#include <qtextcodec.h> 
#include<QWidget>
#include<QApplication>
#include<QLabel>
#include<QMessageBox>


int main(int argc, char **argv)
{
    QApplication app(argc, argv);
    QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
    QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
    QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));


    setWindowTitle(QString::fromLocal8Bit("你"));
    //QWidget::setCaption(QString::fromLocal8Bit("你"));
    QLabel *label = new QLabel("<h2><i>hello </i> "
            "<font color=red>qt!</font></h2>");
    label->show();


    return app.exec();
}




setWindowTitle是在哪个头文件啊??
在QT Assistan里面只查到下面这些说明,没有说包含在哪个头文件。
windowTitle : QString
This property holds the window title (caption).
This property only makes sense for top-level widgets, such as windows and dialogs. If no caption has been set, the title is based of the windowFilePath. If neither of these is set, then the title is an empty string.
If you use the windowModified mechanism, the window title must contain a "[*]" placeholder, which indicates where the '*' should appear. Normally, it should appear right after the file name (e.g., "document1.txt[*] - Text Editor"). If the windowModified property is false (the default), the placeholder is simply removed.
Access functions:
QString    windowTitle () const
void    setWindowTitle ( const QString & )

离线iiiii
只看该作者 1楼 发表于: 2011-01-03
你还没有定义类对象。

可以考虑  label->setWindowTitle(QString::fromLocal8Bit("你"));


改后的:
#include <qtextcodec.h>
#include<QWidget>
#include<QApplication>
#include<QLabel>
#include<QMessageBox>
int main(int argc, char **argv)
{
    QApplication app(argc, argv);
    QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
    QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
    QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
    QLabel *label = new QLabel("<h2><i>hello </i> "
            "<font color=red>qt!</font></h2>");

     label->setWindowTitle(QString::fromLocal8Bit("你"));
    label->show()

    return app.exec();
}
离线qq867814126

只看该作者 2楼 发表于: 2011-01-27
setWindowTitle(QString);是窗口类的成员函数。只有窗口类对象才能调用。
快速回复
限100 字节
 
上一个 下一个