• 10924阅读
  • 4回复

(已解决)可以设置QLCDNumber自动刷新显示不呢? [复制链接]

上一主题 下一主题
离线running
 
只看楼主 正序阅读 楼主  发表于: 2006-07-16
设计:每2秒钟QLCDNumber自动刷新显示数字从60到1

我的代码:
  1. ?
  2. int clocknum=60; ?  
  3. while (clocknum!=0) ?
  4. { ?  
  5. struct itimerval value; ? ?
  6. value.it_value.tv_sec=2; ?  
  7. value.it_value.tv_usec=0; ? ?
  8. value.it_interval=value.it_value; ? ?
  9. setitimer(ITIMER_PROF,&value,NULL); ? ?
  10. QString clockT = QString::number( clocknum, 10 ); ?  
  11. QLCDNumber *number=new QLCDNumber(this); ?  
  12. number->setGeometry(430,40,165,50); ?  
  13. number->display(clockT); ? ?
  14. clocknum=clocknum-1; }


但是QLCDNumber只显示数字1. 请大家帮忙,谢谢!

PS:多谢版大的帮助,10个多月没有Qt,现在写个模块都好生疏了
[ 此贴被running在2006-07-17 09:25重新编辑 ]
离线toby520

只看该作者 4楼 发表于: 2012-02-16
你直接复制版主的代码,存在全角输入的问题
QtQML多多指教开发社区 http://qtclub.heilqt.com
将QtCoding进行到底
关注移动互联网,关注金融
开发跨平台客户端,服务于金融行业
专业定制界面
群号:312125701   373955953(qml控件定做)
离线XChinux

只看该作者 3楼 发表于: 2006-07-16
我用的Qt 4.1.4
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
离线running
只看该作者 2楼 发表于: 2006-07-16
多谢 但没通过 编译错误如下:
[root@localhost qtbase]# make
g++ -c -pipe -Wall -W -O2 -march=i386 -mcpu=i686 -g -DGLX_GLXEXT_LEGACY -fno-use-cxa-atexit -fno-exceptions -DQT_NO_DEBUG -I/usr/lib/qt-3.1/mkspecs/default -I. -I/usr/lib/qt-3.1/include -I.ui/ -I.moc/ -o .obj/qtbase.o qtbase.cpp
qtbase.cpp: In member function `void MyMainWindow::on_timer_timeout()':
qtbase.cpp:46: stray '\201' in program
qtbase.cpp:46: stray '\204' in program
qtbase.cpp:46: parse error before numeric constant
qtbase.cpp:46: stray '\201' in program
qtbase.cpp:46: stray '\204' in program
qtbase.cpp:46: invalid suffix on integer constant
qtbase.cpp:47: stray '\201' in program
qtbase.cpp:47: stray '\204' in program
qtbase.cpp:47: stray '\201' in program
qtbase.cpp:47: stray '\204' in program
qtbase.cpp:47: invalid suffix on integer constant
qtbase.cpp:48: stray '\201' in program
qtbase.cpp:48: stray '\204' in program
qtbase.cpp:48: stray '\201' in program
qtbase.cpp:48: stray '\204' in program
qtbase.cpp:49: stray '\201' in program
qtbase.cpp:49: stray '\204' in program
qtbase.cpp:49: stray '\201' in program
qtbase.cpp:49: stray '\204' in program
qtbase.cpp:49: stray '\201' in program
qtbase.cpp:49: stray '\204' in program
qtbase.cpp:49: stray '\201' in program
qtbase.cpp:49: stray '\204' in program
qtbase.cpp:49: invalid suffix on integer constant
qtbase.cpp:50: stray '\201' in program
qtbase.cpp:50: stray '\204' in program
qtbase.cpp:50: stray '\201' in program
qtbase.cpp:50: stray '\204' in program
qtbase.cpp: At global scope:
qtbase.cpp:51: stray '\201' in program
qtbase.cpp:51: stray '\204' in program
qtbase.cpp:51: stray '\201' in program
qtbase.cpp:51: stray '\204' in program
qtbase.cpp:51: invalid suffix on integer constant
qtbase.cpp: In constructor `MyMainWindow::MyMainWindow(QCanvas&, QWidget*,
  const char*, unsigned int)':
qtbase.cpp:118: stray '\201' in program
qtbase.cpp:118: stray '\204' in program
qtbase.cpp:118: parse error before numeric constant
qtbase.cpp:118: stray '\201' in program
qtbase.cpp:118: stray '\204' in program
qtbase.cpp:118: invalid suffix on integer constant
qtbase.cpp:121: stray '\201' in program
qtbase.cpp:121: stray '\204' in program
qtbase.cpp:121: parse error before numeric constant
qtbase.cpp:121: stray '\201' in program
qtbase.cpp:121: stray '\204' in program
qtbase.cpp:121: invalid suffix on integer constant
qtbase.cpp:122: stray '\201' in program
qtbase.cpp:122: stray '\204' in program
qtbase.cpp:122: stray '\201' in program
qtbase.cpp:122: stray '\204' in program
qtbase.cpp:123: stray '\201' in program
qtbase.cpp:123: stray '\204' in program
qtbase.cpp:123: stray '\201' in program
qtbase.cpp:123: stray '\204' in program
qtbase.cpp:123: invalid suffix on integer constant
qtbase.cpp:124: stray '\201' in program
qtbase.cpp:124: stray '\204' in program
qtbase.cpp:124: stray '\201' in program
qtbase.cpp:124: stray '\204' in program
qtbase.cpp:124: invalid suffix on integer constant
make: *** [.obj/qtbase.o] Error 1
离线XChinux

只看该作者 1楼 发表于: 2006-07-16
main.cpp

#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char **argv)
{
   QApplication app(argc, argv);
   MainWindow mainwindow;
   mainwindow.show();
   return app.exec();
}


mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QtGui/QMainWindow>
#include <QtCore/QTimer>
#include "ui_mainwindow.h"

class MainWindow:public QMainWindow, public Ui::MainWindow
{
   Q_OBJECT
public:
   MainWindow(QWidget *parent=0);
   ~MainWindow();
private slots:
   void on_timer_timeout();
private:
   QTimer timer;
   int m_iCount;
};
#endif



mainwindow.cpp

#include "mainwindow.h"

MainWindow::MainWindow(QWidget *parent):QMainWindow(parent)
{
   setupUi(this);
   m_iCount = 60;
   lcdNumber->display(m_iCount);
   //timer.setInterval(2000);
   connect(&timer, SIGNAL(timeout()), this, SLOT(on_timer_timeout()));
   timer.start(2000);
}

MainWindow::~MainWindow()
{
}

void MainWindow::on_timer_timeout()
{
   m_iCount--;
   if (m_iCount == 0)
   {
       m_iCount = 60;
   }

   lcdNumber->display(m_iCount);
}



mainwindow.ui

<ui version="4.0" >
<author></author>
<comment></comment>
<exportmacro></exportmacro>
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow" >
<property name="geometry" >
  <rect>
  <x>0</x>
  <y>0</y>
  <width>201</width>
  <height>97</height>
  </rect>
</property>
<property name="windowTitle" >
  <string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget" >
  <widget class="QLCDNumber" name="lcdNumber" >
  <property name="geometry" >
  <rect>
    <x>60</x>
    <y>20</y>
    <width>64</width>
    <height>23</height>
  </rect>
  </property>
  </widget>
</widget>
<widget class="QMenuBar" name="menubar" >
  <property name="geometry" >
  <rect>
  <x>0</x>
  <y>0</y>
  <width>201</width>
  <height>20</height>
  </rect>
  </property>
</widget>
<widget class="QStatusBar" name="statusbar" />
</widget>
<pixmapfunction></pixmapfunction>
<resources/>
<connections/>
</ui>

二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
快速回复
限100 字节
 
上一个 下一个