本帖最后由 暗恋 于 2010-9-18 09:52 编辑
以下程序,我想在void ftp::download_mp3()函数里面实现ftp的自动登录,但是运行时无法实现登录。奇怪的是我按界面下的close一次后才运行void ftp::download_mp3()函数下的mp3->setText( tr( "hi" ) ),且测试仿真刚开始时出现warning:could not register server
其它几个按钮按了都立刻有反应,gui界面上总共有以下几个按钮:close,download,其余三个按钮settext是空白。求大侠帮忙解决,特别是阿瑟王!
#include "ftp.h"
#include <qlabel.h>
#include <qpushbutton.h>
#include <qlayout.h>
#include <qvariant.h>
#include <qtooltip.h>
#include <qwhatsthis.h>
#include <qimage.h>
#include <qpixmap.h>
#include "string.h"
#include "stdio.h"
#include "stdlib.h"
#include "unistd.h"
#include "time.h"
#include "sys/ioctl.h"
#include "fcntl.h"
#include "sys/select.h"
#include "sys/types.h"
#include "sys/stat.h"
FILE *fp;
/*
* Constructs a ftp which is a child of 'parent', with the
* name 'name' and widget flags set to 'f'
*/
ftp::ftp( QWidget* parent, const char* name, WFlags fl )
: QWidget( parent, name, fl )
{
if ( !name )
setName( "ftp" );
resize( 588, 480 );
setCaption( tr( "Ftp_Qt_Program" ) );
mp1 = new QPushButton( this, "mp1" );
mp1->setGeometry( QRect( 360, 90, 84, 28 ) );
mp1->setText( tr( "" ) );
mp2 = new QPushButton( this, "mp2" );
mp2->setGeometry( QRect( 360, 150, 84, 28 ) );
mp2->setText( tr( "" ) );
mp3 = new QPushButton( this, "mp3" );
mp3->setGeometry( QRect( 360, 200, 84, 28 ) );
mp3->setText( tr( "" ) );
download = new QPushButton( this, "download" );
download->setGeometry( QRect( 500, 90, 84, 28 ) );
download->setText( tr( "Download" ) );
close = new QPushButton( this, "close" );
close->setGeometry( QRect( 500, 200, 84, 28 ) );
close->setText( tr( "Close" ) );
// signals and slots connections
connect( mp1, SIGNAL( clicked() ), this, SLOT( mp3_1() ) );
connect( mp2, SIGNAL( clicked() ), this, SLOT( mp3_2() ) );
connect( mp3, SIGNAL( clicked() ), this, SLOT( mp3_3() ) );
connect( download, SIGNAL( clicked() ), this, SLOT( download_mp3() ) );
connect( close, SIGNAL( clicked() ), this, SLOT( close() ) );
}
/*
* Destroys the object and frees any allocated resources
*/
ftp::~ftp()
{
// no need to delete child widgets, Qt does it all for us
}
void ftp::download_mp3()
{
fp = popen("ftp -inv 172.17.38.6","w");
if(fp == NULL)
{
perror("popen");
SLOT(close());
}
fprintf(fp,"user sky sky\n");
fprintf(fp,"nlist ./ /root/localfile\n");
pclose(fp);
printf("sujijo");
mp3->setText( tr( "hi" ) );
// qWarning( "ftp::download_mp3(): Not implemented yet!" );
}
void ftp::mp3_1()
{
mp3->setText( tr( "hi" ) );
// qWarning( "ftp::mp3_1(): Not implemented yet!" );
}
void ftp::mp3_2()
{
mp3->setText( tr( "hello" ) );
// qWarning( "ftp::mp3_2(): Not implemented yet!" );
}
void ftp::mp3_3()
{
mp3->setText( tr( "hello" ) );
// qWarning( "ftp::mp3_3(): Not implemented yet!" );
} |