but is not defined as a type

liuyang1943 2009-05-05 09:36:10
老兄,上次说的结贴跳转问题最后用键盘时间代替了信号,但同样存在以前的问题,就是一个界面不能让两个或多个其他界面跳转,否则出现
is used as a type but is not defined as a type
的提示,你之前说的让主界面显示所有其他界面我尝试了下都失败了,实在没辙了,老兄能不能把你的代码贴上来我参考下,看看具体是怎么实现的。
...全文
207 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
liuyang1943 2009-05-05
  • 打赏
  • 举报
回复
信号可以绑定,键盘事件可以绑定吗?
  • 打赏
  • 举报
回复

VPN_load::VPN_load(QMainWindow *parent)
: QMainWindow(parent)
{
setupUi(this);
//bool op;
//lineEdit_account->installEventFilter(this);
//lineEdit_password->installEventFilter(this);
//op=lineEdit_account->isVisibleTo ( this);
//op=lineEdit_password->isVisibleTo ( this);
lineEdit_password->setEchoMode ( QLineEdit::Password );
pushButton_configure->setCursor ( Qt::PointingHandCursor);
pushButton_cancel->setCursor ( Qt::PointingHandCursor);
connect(&server_a, SIGNAL(show_man()), &usr, SLOT(show_man_acc())); //把server_a界面的信号跟show_man_acc()这个slot绑定
connect(pushButton_configure, SIGNAL(clicked()), this, SLOT(check_load()));
connect(pushButton_cancel, SIGNAL(clicked()), this, SLOT(cancel_line()));
QFile file("last_load.txt");
QChar c;
char buf[200];
qint64 read_bytes;;
if(!file.open(QIODevice::ReadWrite))
QMessageBox::information( this, "debug", "Fail to open last load file!" );
read_bytes=file.readLine(buf,200);
cout<<"read acc:"<<read_bytes<<"bytes"<<endl;
last_acc="";
last_acc.append(buf);
//last_acc.remove(read_bytes-1,read_bytes-1);
file.close();
lineEdit_account->setText ( last_acc );

}


void VPN_load::show_man_acc()
{
printf("load getsignal to show man_acc.\n");
man_access.show(); //这里show出man_access
}



这样应该就可以了啊
  • 打赏
  • 举报
回复


class VPN_load : public QMainWindow, public Ui::MainWindow_load
{
Q_OBJECT
public:
VPN_load(QMainWindow *parent = 0);
~VPN_load();
man_usr man_access;
void keyPressEvent( QKeyEvent * event); //for key enter
void showEvent ( QShowEvent * event );
void hideEvent ( QHideEvent * event );
//bool eventFilter(QObject *target,QEvent *event);

private:
VPN_usr usr; //这里2个子界面
server server_a;
QString last_acc;

private slots:
int check_load();
void cancel_line();
void show_man_acc();

};


  • 打赏
  • 举报
回复

/************main.cpp ****************//
//这里主界面就是VPN_load *dialog_load
//#include "ui_VPN.h"
#include <QApplication>
#include "vpn_usr.h"
#include "vpn_load.h"

//#include <QDialog>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
//VPN_usr *dialog = new VPN_usr;
VPN_load *dialog_load = new VPN_load;
//QDialog *dialog = new QDialog;
dialog_load->show();
return app.exec();
}

  • 打赏
  • 举报
回复
汗,你等等,我看看啊。
  • 打赏
  • 举报
回复
QString str=label_2->text();

label_2是控件名的话,一般是指针
liuyang1943 2009-05-05
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 hairetz 的回复:]
引用 5 楼 liuyang1943 的回复:
信号可以绑定,键盘事件可以绑定吗?


键盘事件不需要绑定啊,你在类里重载键盘事件处理函数就可以了啊。
[/Quote]

你的意思是用键盘事件来触发信号完成显示?
我还想了个办法因为我的很多界面是相似的,那么就不改变界面只改变界面上的文字和图片。
我的做法是当有按键按下时根据label的值来判定应该显示哪个界面,这样的话可以省去不少功夫,不过我在取出label中的值时遇到点麻烦,我的代码是这样的:
if(event->key() == Qt::Key_Down)
{QString str=label_2.text();
if(str=="View Delay"){
label_2->setText ("View Config");
}
//this->hide();

}
通过判定label_2的值来确定下一步操作,不过编译的时候步能通过,提示:request for member 'text' in (this + 20)->Ui_ViewMenuConfig::label_2,which is of non-aggregate type 'QLabel*'
什么原因?

bxhzct 2009-05-05
  • 打赏
  • 举报
回复
呵呵,Qt很猛,支持
amossavez 2009-05-05
  • 打赏
  • 举报
回复
给你们顶上去!!慢慢讨论!!
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 liuyang1943 的回复:]
信号可以绑定,键盘事件可以绑定吗?
[/Quote]

键盘事件不需要绑定啊,你在类里重载键盘事件处理函数就可以了啊。

23,121

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧