質問

I'm trying to learn some Qt and c++ using windows (with linux as usual I had no problem). Installed Qt 5.2.1 and vs add-in.

When I create the most simple project (a dialog and a label) I can run it no problem unless I try to change something in code, like:

SimpleLLabel::SimpleLLabel(QWidget *parent)
    : QMainWindow(parent)
{
    ui.setupUi(this);
    label->hide();
}

I get the following error:

1> simplellabel.cpp 1>simplellabel.cpp(8): error C2065: 'label' : identificador no declarado 1>simplellabel.cpp(8): error C2227: el operando izquierdo de '->hide' debe señalar al >tipo class/struct/union/generic

Translates to undeclared identifier for label.

label exists in the "generated files" folder by Qt (name ui_simplellabel.h). All files in this directory appear with a no entry sign. I've tried adding them to "not excluded from compilation" but didn't solved my problem. Also the folder "generated files" appears on project properties > c++ > additional directories.

Any hint on how to get VS2012 to correctly link and compile my files?

役に立ちましたか?

解決

You are looking for this:

ui.label->hide();
^^^

Your label is part of the generated ui file and so on. You probably have a ui member, so that is what you need to use.

I would personally work with a heap object, aka. pointer, instead of stack object, but that is not why you are getting the compilation issue for sure.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top