我正在开发一个程序,其中包含MainWindow和QWidget中的一个名为diagrama的Widget,这是我主窗口的中央部件。
现在,我创建了一个我无法使用的对象。
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
Diagrama* diagrama=new Diagrama();
setCentralWidget(diagrama);
....}
void MainWindow::on_actionCor_triggered()
{
QColor newcolor=QColorDialog::getColor(Qt::black,this,"Cor do pincel");
if(newcolor.isValid()){
diagrama->setPenColor(newcolor);
##qt do not recognize the object diagrama, and i can't access the function of that class}
}
我如何使用它?我在一些示例中看到了这一点,即创建该类的对象并稍后在函数中使用它。
我尝试使用: diagrama = new Diagrama();
但是它也不起作用,我真的不知道该怎么办。