• 4694阅读
  • 2回复

[讨论]程序运行时出现两个对话框? [复制链接]

上一主题 下一主题
离线青春岁月
 

只看楼主 倒序阅读 楼主  发表于: 2011-04-28
不知到为什么?
一个主界面,一个文件列表对话框

#include "mainwindow.h"

#include "stdio.h"
#include "unistd.h"
#include "stdlib.h"
#include "sys/types.h"
#include "sys/stat.h"
#include "sys/ioctl.h"
#include "fcntl.h"
#include "linux/fs.h"
#include "errno.h"
#include "string.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{

    fd = new QFileDialog(this);

  //  fd->setDirectory(tr("/"));

    fileBtn = new QPushButton(tr("File"),this);
    line_mysongname = new QLineEdit(this);

    fileBtn->move(0,0);
    line_mysongname->move(100,0);

    playBtn = new QPushButton(tr("play"),this);
    playBtn->move(0,30);

    connect(fileBtn,SIGNAL(clicked()),this,SLOT(choose_songname()));
    connect(playBtn,SIGNAL(clicked()),this,SLOT(play_song()));

}

MainWindow::~MainWindow()
{

}

void MainWindow::choose_songname()
{
    QString str;

    fd->setFileMode(QFileDialog::ExistingFile);
    fd->setNameFilter(tr("Music(*.mp3)"));
    fd->setViewMode(QFileDialog::Detail);

    if(fd->exec())
    {
        songname = fd->selectedFiles();
    }


    str = songname.at(0);
    mysongname = songname.at(0);
    str.remove(tr("/home/wzk/Music/"));
    str.chop(4);

    line_mysongname->setText(str);
}


void MainWindow::play_song(void)
{
    char *ch;
    QByteArray byte;
    QString temp;

    temp = "./madplay -i " + mysongname;
    byte = temp.toAscii();
    ch = byte.data();

    system(ch);

}

go!   go!  go!  go!
离线dbzhang800

只看该作者 1楼 发表于: 2011-04-28
1. 因为你的代码就是这么写的。或者不妨说说你的 new QFileDialog(this); 有别的什么意图??

题外:不清楚这是不是你真实代码,如果是的话,建议先看看QMainWindow的使用方法。
离线npuwj
只看该作者 2楼 发表于: 2011-04-30
where is  main()?
快速回复
限100 字节
 
上一个 下一个