• 128375阅读
  • 117回复

【原创】常见的几个Qt编程问题的处理 [复制链接]

上一主题 下一主题
离线mwystd

只看该作者 40楼 发表于: 2008-05-11
  求助:
我装了qt后,qmake 生成makefile时出现下面问题,请问是什么问题,怎么解决?

Could not find mkspecs for your QMAKESPEC after trying:
        /usr/lib/qt-3.1
        /usr/lib/qt-3.1
Error processing project file: /home/user_name/qt-x11-opensource-src-4.2.2/conversion1/conversion.pro
离线ny13524
只看该作者 41楼 发表于: 2008-07-15
好贴
多谢分享!
离线soul
只看该作者 42楼 发表于: 2008-07-24
好东西,感谢楼主分享了~
离线hatmann1944

只看该作者 43楼 发表于: 2008-07-29
初学QT
怎么会出现这样的错误请问
我头文件都包含了呀      #include <QtGui/QTextEdit>
环境是UBUNTU+QT4
用QDEVELOP
error: ‘class QTextEdit’ has no member named ‘text’
离线txiejun
只看该作者 44楼 发表于: 2008-08-04
楼主,我这儿遇到个问题,请帮忙解决一下:
http://www.qtcn.org/bbs/read.php?tid=11985
三分天注定,七分靠打拼,爱拼才会赢!
离线txiejun
只看该作者 45楼 发表于: 2008-08-04
用Qt 4打开一个txt的文件并导入表格中,为什么重新打开或打开别的txt文件就出错?
请教各位高手:
问题说明:有一个文本文件(test.txt)里面是一行是一条记录
我需要把所有的记录读到一个表里
我用Qt 4的Designer 设计了一个主界面并在上面画了个QTableWidget 控件,生成一个ui文件(opentext.ui),
运用的编译器是VS.net2003的c++编译器
但是我现在的问题是能够读入,但是当重新读入时或读入其他的txt文件时就出错了,请问问题在哪儿?
下面是部分代码:
//opentext.h

#ifndef OPENTEXT_H
#define OPENTEXT_H

#include <QMainWindow>
#include <QTableWidgetItem>
#include <QTableWidget>

#include "ui_opentext.h"
class OpenText : public QMainWindow, public Ui::OpenText
{
    Q_OBJECT
public:
    OpenText(QWidget *parent = 0);
    bool readFile(const QString &fileName);
    bool moveFile(const QString &fileName);
    bool loadFile(const QString &fileName);
    void clear(QTableWidget *,int ,int);
private slots:
    void open();
    bool save();
    void about();
private:
    void createActions();
    bool saveFile(const QString &fileName);
    bool okToContinue();
    void setCurrentFile(const QString &fileName);
    QString strippedName(const QString &fullFileName);
    QString curFile;
   

};
#endif


//opentext.cpp
#include <QtGui>

#include "opentext.h"
#include <QTextStream>
#include <QStringList>

OpenText::OpenText(QWidget *parent)
    : QMainWindow(parent)
{
    setupUi(this);//初始化主界面
    createActions();
    clear(opentable,100,14);

    setCurrentFile("");

   
}

void OpenText::createActions()
{
    OpenAction->setShortcut(tr("Ctrl+O"));
    OpenAction->setStatusTip(tr("Open an existing txt file"));
    connect(OpenAction, SIGNAL(triggered()), this, SLOT(open()));

    SaveAction->setShortcut(tr("Ctrl+S"));
    SaveAction->setStatusTip(tr("Save the txt to disk"));
    connect(SaveAction, SIGNAL(triggered()), this, SLOT(save()));

    AboutAction->setStatusTip(tr("Show the application's About box"));
    connect(AboutAction, SIGNAL(triggered()), this, SLOT(about()));
}


bool OpenText::readFile(const QString &fileName)
{    //读入文件
   
    QFile file(fileName);
    if (!file.open(QIODevice::ReadOnly))
    {
        QMessageBox::warning(this, tr("OpenText"),
                            tr("Cannot read file %1:\n%2.")
                            .arg(file.fileName())
                            .arg(file.errorString()));
        return false;

    }
    QTextStream in(&file);
   

    int row=0;
    int clm=0;
//    clear(opentable);
    while (!in.atEnd())
    {
        QString strLineText = in.readLine();
        QStringList list1 = strLineText.split(QRegExp("\\s+"),QString::SkipEmptyParts);//以空格为基础拆分字符串
        QTableWidgetItem  *newItem=new QTableWidgetItem[list1.size()];
       
        if(list1.size()>clm&&list1.size()<=14)
        {//保存最大列
            clm=list1.size();
        }
        else if(list1.size()>14)
        {
            clm=14;
        }
       

        opentable->setRowCount(row+1);
        for(int column=0;column<list1.size();column++)
        {
            opentable->setItem(row, column, &newItem[column]);
            newItem[column].setText(list1.value(column));
        }
       
        ++row;
       
    }
   
    file.close();
   
    return true;
}


bool OpenText::okToContinue()
{
    if (false/*filechanged(opentable)*/)
    {
        int r = QMessageBox::warning(this, tr("text file"),
                        tr("The document has been modified.\n "
                          "Do you want to save your changes?"),
                        QMessageBox::Yes | QMessageBox::Default,
                        QMessageBox::No,
                        QMessageBox::Cancel | QMessageBox::Escape);
        if (r == QMessageBox::Yes) {
            return save();
        } else if (r == QMessageBox::Cancel) {
            return false;
        }
    }
    return true;
}
void OpenText::open()
{
    if (okToContinue()) {
        QString fileName = QFileDialog::getOpenFileName(this,
                                  tr("Open Text File"), ".",
                                  tr("txt files (*.txt)"));
        if (!fileName.isEmpty())
            loadFile(fileName);
    }
}


bool OpenText::save()
{
    /*
    if (fileName.isEmpty()) {
        return saveAs();
    } else {
        return saveFile(fileName);
    }
    */
    return true;
}



bool OpenText::loadFile(const QString &fileName)
{
    if (!readFile(fileName)) {
        statusBar()->showMessage(tr("Loading canceled"), 2000);
        return false;
    }
    setCurrentFile(fileName);
    statusBar()->showMessage(tr("File loaded"), 2000);
    return true;
}


void OpenText::clear(QTableWidget *table,int row,int clm)
{
    table->setRowCount(0); //此行出错
    table->setColumnCount(0);
    table->setColumnCount(clm);
    table->setRowCount(row);
    QString filetext[14]={"Number","ID","price","column4","column5","column6","column7","column8","column9","column10","column11","column12","column13","column14"};
    for (int i = 0; i < 14; ++i) {
        QTableWidgetItem *item = new QTableWidgetItem;
        item->setText(filetext);
        table->setHorizontalHeaderItem(i, item);
       
       
    }
   
    opentable->setCurrentCell(0, 0);
}

void OpenText::setCurrentFile(const QString &fileName)
{
    curFile = fileName;
    setWindowModified(false);

    QString shownName = "Untitled";
    if (!curFile.isEmpty()) {
        shownName = strippedName(curFile);
    }

    setWindowTitle(tr("%1[*] - %2").arg(shownName)
                                  .arg(tr("OpenText")));
}
QString OpenText::strippedName(const QString &fullFileName)
{
    return QFileInfo(fullFileName).fileName();
}

void OpenText::about()
{
    QMessageBox::about(this, tr("About OpenText"),
            tr("<h2>OpenText 1.1</h2>"
              "<p>Copyright © 2008 Software Inc."
              "<p>OpenText is a small application that "
              "demonstrates QAction, QMainWindow, QMenuBar, "
              "QStatusBar, QTableWidget, QToolBar, and many other "
              "Qt classes."));
}
三分天注定,七分靠打拼,爱拼才会赢!
离线abel
只看该作者 46楼 发表于: 2008-08-04
好铁!!
离线baoxiaobao
只看该作者 47楼 发表于: 2008-08-12
问:用QT编程如何实现:在一行字上右击鼠标,出现一些链接的菜单?就像我们现在可用的鼠标功能一样?先谢谢了!
离线peiter

只看该作者 48楼 发表于: 2008-09-03
Qt4.4已经加强了打印报表等功能的支持
http://doc.trolltech.com/4.4/qt4-4-intro.html#printing-system-improvements
有C#.NET/Qt开发业务相商的朋友请发电子邮件到pj_soft@126.com
有技术问题的朋友请在论坛里发贴提问,不要通过私人短信或者QQ/MSN提问讨论,谢谢合作
邮件:  pj_soft@126.com
即时通讯: QQ: 303782414  MSN: mjqznet@yahoo.com.cn
网址: http://t811.uu1001.com
我的博客http://peiter.blog.xunlei.com/
操作系统: Fedora9
主要开发方向: C++/Qt程序开发,C#/ASP.NET
离线cuis2324

只看该作者 49楼 发表于: 2008-10-13
好好好!又学到不少,希望斑竹多出些faq解答
离线zhanghong123
只看该作者 50楼 发表于: 2008-10-20
请问版主,如何实现qt3下linux命令的执行
离线jackxo1981
只看该作者 51楼 发表于: 2008-10-22
Qt怎么判断当前盘符是不是USB
Qt怎么判断当前盘符是不是USB?
离线xdman

只看该作者 52楼 发表于: 2008-10-29
谢谢斑竹,东西很多阿!
离线bgl8888
只看该作者 53楼 发表于: 2008-11-28
寻他千百度,原来在此处
离线lennyf

只看该作者 54楼 发表于: 2009-01-06
很好!先学习了。
离线eastfind
只看该作者 55楼 发表于: 2009-01-10
有帮助,感谢好帖
离线tianjtisng
只看该作者 56楼 发表于: 2009-03-08
请问版主:
QT如何写守护进程/服务程序?
[ 此帖被tianjtisng在2009-03-08 13:27重新编辑 ]
离线joetaiyuan
只看该作者 57楼 发表于: 2009-03-26
顶!学习了。多谢。
离线qiudeyezi
只看该作者 58楼 发表于: 2009-04-05
请问楼主,qt3中是否有内存回收的函数可以使用?
离线XChinux

只看该作者 59楼 发表于: 2009-04-05
引用第56楼tianjtisng于2009-03-08 13:14发表的  :
请问版主:
QT如何写守护进程/服务程序?


目前与Qt库没啥关系(没有进行封装),只能自己根据不同的平台API接口自己调用。
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
离线dayong419
只看该作者 60楼 发表于: 2009-04-16
很不错的,顶
离线hys97

只看该作者 61楼 发表于: 2009-04-30
好贴!学习中.
离线ggcool
只看该作者 62楼 发表于: 2009-05-03
不顶就白学qt,拜读了
离线潜行
只看该作者 63楼 发表于: 2009-05-21
谢楼主
离线teeker
只看该作者 64楼 发表于: 2009-07-07
急问楼主高人
急问,本人在linux下用开源的QTCreator 编译好了OCI驱动库,并把它放在当前plugin\dirvers下面,但建立客户端连接oracle程序就是找不到OCI驱动?提示dirver  not load.

谢谢!
离线naked_fox
只看该作者 65楼 发表于: 2009-07-16
很好,谢谢阿
离线午小夜

只看该作者 66楼 发表于: 2009-07-23
好帖.崇拜
[操作系统版本]  Windows XP;Linux Ubuntu;Linux Fedora;
[Qt SDK版本]    4.7.0
[SDK 发布日期]  2010.05
[IDE(集成开发环境)] QtCreator
个人网页:http://hi.baidu.com/午小夜
學歷:Royal Jalidon
离线wangjian
只看该作者 67楼 发表于: 2009-07-29
太谢谢了 支持楼主
离线旺旺
只看该作者 68楼 发表于: 2009-08-08
关于QT4移植的问题!很急!!!!!!!!!!!!!!!!!!
cp custom-linux-cassiopeia-g++.h custom-linux-arm-g++.h
cp custom-linux-cassiopeia-g++.cpp custom-linux-arm-g++.cpp
但我执行这段的时候,系统提示我说  没有custom-linux-cassiopeia-g++.h custom-linux-cassiopeia-g++.cpp& 我不知道是什么原因啊!
custom-linux-cassiopeia-g++  想问问这是个什么编译器!我/mnt/nfs/qtopia/src/librarise/qtopiabash 里面只有custom-linux-sharp-g++ custom-linux-generic-g++.啊!不晓得这是为什么!那位大侠给点提示啊!????????
而且我在./configure -silent -release

-image /tmp/qtopia_target

-prefix /tmp/qtopia_target

-xplatform linux-arm-g++ -arch arm -no-qvfb

-displaysize 320x240 -no-modem

-extra-qtopiacore-config "-release -xplatform qws/linux-arm-g++ -embedded arm -opengl -qconfig qpe -qt-sql-sqlite

-depths 4,8,16,32 -qt-kbd-usb -no-kbd-tty -qt-mouse-linuxtp "
2>../qtopiaconfgureERR.txt
后,然后make 总是会报错!然后就编译不通了!这是什么原因啊!?????
我第一次configure 的时候就只是./configure -silent -release  后面没有加参数,这样就能顺利编译成功!但是这样编译后,我始终都找不到qpe,是不是没有生成qpe啊!???????
离线fshjy
只看该作者 69楼 发表于: 2009-08-21
顶版主~~ 以后要多学习了~
离线zs280

只看该作者 70楼 发表于: 2009-08-27
版主 你太伟大了....谢谢你这种无私精神.....
离线jialiang0601

只看该作者 71楼 发表于: 2009-10-17
好贴,好贴! 多谢多谢!
离线zhbit2008
只看该作者 72楼 发表于: 2009-10-19
版主是一个强大的牛人。。
离线timleaf

只看该作者 73楼 发表于: 2009-10-29
多谢斑竹分享………………
爱你选择的,选择你所爱的……
离线moxie7918
只看该作者 74楼 发表于: 2009-10-29
请问 qt4  嵌入式版本 要使用ps/2鼠标键盘需注意那些设置  
我一般在/etc/profile 中制定qws 鼠标协议  在qt4 的 configure 中加上 qt-mouse-pc   qt-kbd-pc

但我发现刚进入linux系统后运行程序就会死机,键盘鼠标都动不了 但线程实现的实时时钟还工作正常。
我用qt-embedded-linux-opensource-src-4.4.3.tar.gz,linux打开framebuffer。
离线zyq840112

只看该作者 75楼 发表于: 2009-11-10
好帖,谢谢分享!
离线chendaqun
只看该作者 76楼 发表于: 2009-11-10
fdsafdsdsafdsafdsafdsa
离线zy0827
只看该作者 77楼 发表于: 2009-11-12
非常感謝.
离线benbenmajia

只看该作者 78楼 发表于: 2009-12-03
高人~!
安然.....
离线hujin50w
只看该作者 79楼 发表于: 2009-12-09
用qt creator 运行examples里的程序   大多的程序都能run。  不过有几个就不行。比如打开Music Player Example 运行就 提示错误: collect2: ld returned exit status.

如何解决。谢谢。
快速回复
限100 字节
 
上一个 下一个