天嵌 ARM开发社区

 找回密码
 注册
查看: 3967|回复: 11

qt编译通过了,但运行不了

[复制链接]
暗恋 发表于 2010-9-18 09:44:10 | 显示全部楼层 |阅读模式
本帖最后由 暗恋 于 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!" );
}
天嵌_support1 发表于 2010-9-18 12:12:27 | 显示全部楼层
本帖最后由 embedsky_lxt 于 2010-9-18 12:13 编辑

我把你的IP换成开板的 192.168.1.6
可以用啊,你的程序。就是写文件的时候权限不够,下面是我的输出:

Starting /home/paul/Desktop/Testing_Programs/MyFTP/MyFTP...
Connected to 192.168.1.6.
220 EmbedSky FTP server (Version 6.4/OpenBSD/Linux-ftpd-0.17) ready.
331 Password required for sky.
230 User sky logged in.
local: /root/test.txt: Permission denied
Remote system type is UNIX.
Using binary mode to transfer files.
221 Goodbye.

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
 楼主| 暗恋 发表于 2010-9-18 12:48:58 | 显示全部楼层
权限不够,那个文件权限不够?
 楼主| 暗恋 发表于 2010-9-18 12:52:38 | 显示全部楼层
embedsky_lxt,谢谢你,但是我在终端上面逐个命令打上去是可以实现的
 楼主| 暗恋 发表于 2010-9-18 13:05:16 | 显示全部楼层
大侠,会不会是缺少什么库,c++的库导致呢?我把文件权限也改了,还是不行
天嵌_support1 发表于 2010-9-18 14:30:24 | 显示全部楼层
我的意思是你的程序可以运行的,是正确的。
只是要在被连接的机器上创建文件,没有这个权限。
获取改个路径就可以。和你的程序无关
 楼主| 暗恋 发表于 2010-9-18 15:11:24 | 显示全部楼层
本帖最后由 暗恋 于 2010-9-18 15:14 编辑

非常感谢你,nlist ./ /root/localfile这句话不是在本机上创建一个localfile的文件吗?然后程序连接到另外一台机(172.17.38.6),把目录写到本机的/root/localfile下,况且我也试过在本机先建立localfile,权限也改成777了,还是不行。大侠embedsky_lxt ,请你再帮帮忙
 楼主| 暗恋 发表于 2010-9-18 15:25:29 | 显示全部楼层
大侠,不好意思,还有一个提示:warning:QSocket::writeBlock:Socket is not open
 楼主| 暗恋 发表于 2010-9-18 15:29:24 | 显示全部楼层
这个提示不是每次都出现,还有是不是与什么环境变量设置有关,网上很难查得到
天嵌_support1 发表于 2010-9-18 15:57:31 | 显示全部楼层
我是登录我的开发板,程序在PC上运行,用 nlist命令 列开发板上的 /root/tmp 目录的文件。
读取保存到 PC的 /opt/text.txt 文件上,可以的。
 楼主| 暗恋 发表于 2010-9-18 16:05:40 | 显示全部楼层
那可能是平台依赖性问题了,请问你的qt是什么版本,还有你的是rethat9.0吗?
天嵌_support1 发表于 2010-9-18 18:52:22 | 显示全部楼层
我用的是 debian.
用 Creator 编译你的程序
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

i.MX8系列ARM cortex A53 M4 工控板上一条 /1 下一条

Archiver|手机版|小黑屋|天嵌 嵌入式开发社区 ( 粤ICP备11094220号-2 )

GMT+8, 2024-9-27 23:23 , Processed in 1.031290 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表