I have defined some QTableWidget
by using inheritance and some buttons by Qt Creator.
我通过使用继承和Qt创建者的一些按钮定义了一些QTableWidget。
Now I'm trying to connect a signal from my button to a slot from my QTableWidget
.
现在,我正在尝试将一个信号从按钮连接到QTableWidget的一个插槽。
Here in main()
I have defined my Food object of self defined(re-defined) QTableWidget
:
在main()中,我定义了自定义(重新定义)QTableWidget的Food对象:
Table Food(&w,3,700,50,610,getdata_foodtabel());
And in next line I tried to connect it with my QPushButton
object(orderButton):
在下一行,我尝试将它与我的QPushButton对象(orderButton)连接:
QObject::connect(Ui::MainWindow::orderButton, SIGNAL(w.on_orderButton_clicked()),&Food, SLOT(Food.get_number()));
And in this line I get this error:
在这一行,我得到了这个误差:
error: invalid use of non-static data member 'Ui_MainWindow::orderButton'
QPushButton *orderButton;
^
And also get number is a self defined public slot in Table class
get number是表类中自定义的公共槽
can any body tell me why is this error for? and what should I do to fix it?
有没有人能告诉我为什么这个错误?我该怎么做才能修复它呢?
my table's constructor int Table.cpp:
我的表的构造函数int table .cpp:
Table::Table(QWidget *Parent,int row,int X,int Y,int height,std::vector <std::vector <std::string > > food)
:QTableWidget(food.size(),3,Parent)
{
this->setGeometry(QRect(X,Y,321,height));
this->setStyleSheet(QStringLiteral("background-color: rgb(206, 255, 255);"));
this->row=food.size();
for(int i=0;i<this->row;i++)
this->food.push_back(food[i]);
for (int i=0;i<this->row;i++)
{
// this->food[i][0]=names[i];
// this->food[i][1]=costs[i];
this->setCellWidget(i,0,new label(QString::fromStdString(food[i][0])));
this->setCellWidget(i,1,new label (QString::fromStdString(food[i][1])));
this->setCellWidget(i,2,new QSpinBox);
}
}
and my main function:
我的主要功能:
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
Table Drinks(&w,3,40,50,280,getdata_drinktabel());
Drinks.setHorizontalHeaderLabels(QString("نوشیدنی;قیمت;تعداد").split(";"));
Table Desert(&w,3,40,380,280,getdata_desertabel());
Desert.setHorizontalHeaderLabels(QString("دسر;قیمت;تعداد").split(";"));
Table Appetizer(&w,3,370,50,610,getdata_beforetabel());
Appetizer.setHorizontalHeaderLabels(QString("پیش غذا;قیمت;تعداد").split(";"));
Table* Food=new Table(&w,3,700,50,610,getdata_foodtabel());
Food->setHorizontalHeaderLabels(QString(" غذا;قیمت;تعداد").split(";"));
Food->setStyleSheet(QStringLiteral("background-image: url(:/soltani-edited1.jpg);"));
QObject::connect(Ui::MainWindow::orderButton, SIGNAL(clicked()),Food, SLOT(Food.get_number()));
w.show();
return a.exec();
}
1 个解决方案
#1
0
I fixed it in another way...
我用了另一种方法……
I just inherited a class from QPushButton
and connected it's signal to Food
's slot.
我刚刚从QPushButton继承了一个类并将它的信号连接到Food的插槽上。
#1
0
I fixed it in another way...
我用了另一种方法……
I just inherited a class from QPushButton
and connected it's signal to Food
's slot.
我刚刚从QPushButton继承了一个类并将它的信号连接到Food的插槽上。