青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

2009年3月24日

用VC調整顯示器的分辨率 zz

 

調整分辨率的代碼如下:
DEVMODE dm;
 dm.dmSize = sizeof(DEVMODE) ;
 EnumDisplaySettings(NULL,ENUM_CURRENT_SETTINGS,&dm);
 if(dm.dmPelsHeight!=1024||dm.dmPelsWidth!=1280){
  if(AfxMessageBox("為了達到最好的顯示效果,建議您使用1280*1024的分辨率,確定嗎?",MB_YESNO)==IDYES){
   LONG result;
   dm.dmBitsPerPel = 32;
   dm.dmPelsHeight = 1024;
   dm.dmPelsWidth = 1280;
   dm.dmFields = DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
   result = ChangeDisplaySettings(&dm,0);
  }
 }
“如果要在程序啟動時自動自動調整到合適的分辨率,可以將其加入到View的OnInitialUpdate()中,并記錄下dm.dmPelsHeight和dm.dmPelsWidth的值。
要在程序結束時自動調整回原有分辨率,可在MainFrame的OnClose()中用以上代碼將其改回原值。”

如果要在程序啟動時自動自動調整到合適的分辨率,可以將其加入到app的InitInstance()中,并記錄下dm.dmPelsHeight和dm.dmPelsWidth的值。
要在程序結束時自動調整回原有分辨率,可在APP的ExitInstance中用以上代碼將其改回原值。”

posted @ 2009-03-24 11:19 Alina-zl 閱讀(551) | 評論 (0)編輯 收藏

2008年12月30日

vc2005中沒有classwizard這個命令了 2005下怎么添加鼠標事件

vc2005中沒有classwizard這個命令了

取代classwizard 中的添加消息映射,添加類,等等的功能主要在屬性窗口中

鼠標事件不要手動添加,最好使用下述方法

比如添加消息映射。你選定了一個類后,在屬性點擊右鍵 選擇屬性
在屬性窗口中點擊那個像閃電樣的 圖標 就會出現 一系列的消息供你選擇 ,點擊 小方快樣子的圖標 就會出現虛函數或者重載

至于添加類,直接在工程名稱上點右鍵 選擇 添加類的命令 即可

添加變量 ,可以在類名稱上點右鍵,選擇添加變量

posted @ 2008-12-30 11:51 Alina-zl 閱讀(892) | 評論 (0)編輯 收藏

2008年12月16日

'IDD_DIALOG1' : undeclared identifier

error   C2065:   'IDD_DIALOG1'    undeclared   identifier  

解決辦法:

加#include   'resource.h'

posted @ 2008-12-16 19:20 Alina-zl 閱讀(1992) | 評論 (1)編輯 收藏

2008年11月21日

MFC與namespace的沖突問題

把代碼從QT移植到MFC的時候,這個文件vecmat.h,出現了如下錯誤:
error C2143: syntax error : missing ',' before ')'
error C2143: syntax error : missing ';' before '}'
error C2059: syntax error : ')'
fatal error C1004: unexpected end-of-file found
等等。
vecmat.h源代碼如下:

#ifndef  VECMAT_H
# define VECMAT_H

# include <cmath>
# include <vector>
# include <iostream>

 

namespace vecmat {

 namespace internal {

  template <bool B>
  struct is_false {};

  template <>
  struct is_false<false> {
   static inline void ensure() {}
  };

 } // end of namespace internal

 //
 //  Vector class
 //    - T: value type
 //    - N: dimension
 //
 /////////////////////////////////////////////////////////////////////////////

 template <class T, unsigned N>
 class Vector
 {
 public:

  typedef T value_type;

  // constructors

  inline Vector() {
   for (unsigned i = 0; i < N; i++)
    _coord[i] = 0;
  }

  ~Vector() {
   internal::is_false<(N == 0)>::ensure();
  }

  template <class U>
  explicit inline Vector(const U tab[N]) {
   for (unsigned i = 0; i < N; i++)
    _coord[i] = (T)tab[i];
  }

  template <class U>
  explicit inline Vector(const std::vector<U>& tab) {
   for (unsigned i = 0; i < N; i++)
    _coord[i] = (T)tab[i];
  }

  template <class U>
  explicit inline Vector(const Vector<U, N>& v) {
   for (unsigned i = 0; i < N; i++)
    _coord[i] = (T)v[i];
  }

  // accessors

  inline value_type  operator[](const unsigned i) const {
   return _coord[i];
  }

  inline value_type& operator[](const unsigned i) {
   return _coord[i];
  }

  static inline unsigned dim() {
   return N;
  }

  // various useful methods

  inline value_type norm() const {
   return (T)sqrt(squareNorm());
  }

  inline value_type squareNorm() const {
   return (*this) * (*this);
  }

  inline Vector<T, N>& normalize() {
   value_type n = norm();
   for (unsigned i = 0; i < N; i++)
    _coord[i] /= n;
   return *this;
  }

  inline Vector<T, N>& normalizeSafe() {
   value_type n = norm();
   if (n)
    for (unsigned i=0; i < N; i++)
     _coord[i] /= n;
   return *this;
  }

  inline Vector<T, N>& min(const Vector<T, N>& v) {
   for (unsigned i=0; i < N; i++)
    if (_coord[i]  > v._coord[i])
     _coord[i] = v._coord[i];
   return *this;
  }

  inline Vector<T, N>& max(const Vector<T, N>& v) {
   for (unsigned i=0; i < N; i++)
    if (_coord[i]  < v._coord[i])
     _coord[i] = v._coord[i];
   return *this;
  }

  inline const value_type* address() const {
   return _coord;
  }

  // classical operators

  template <class U>
  inline Vector<T, N>& operator=(const Vector<U, N>& v) {
   if (this != &v)
    for (unsigned i = 0; i < N; i++)
     _coord[i] = (T)v[i];
   return *this;
  }

  template <class U>
  inline Vector<T, N>& operator+=(const Vector<U, N>& v) {
   for (unsigned i = 0 ; i < N; i++)
    _coord[i] += (T)v[i];
   return *this;
  }

  template <class U>
  inline Vector<T, N>& operator-=(const Vector<U, N>& v) {
   for (unsigned i = 0 ; i < N; i++)
    _coord[i] -= (T)v[i];
   return *this;
  }

  template <class U>
  inline Vector<T, N>& operator*=(const U r) {
   for (unsigned i = 0 ; i < N; i++)
    _coord[i] *= r;
   return *this;
  }

  template <class U>
  inline Vector<T, N>& operator/=(const U r) {
   if (r)
    for (unsigned i = 0 ; i < N; i++)
     _coord[i] /= r;
   return *this;
  }


  inline bool operator==(const Vector<T, N>& v) const {
   for(unsigned i = 0; i < N; i++)
    if (_coord[i] != v[i])
     return false;
   return true;
  }

  inline bool operator!=(const Vector<T, N>& v) const {
   for(unsigned i = 0; i < N; i++)
    if (_coord[i] != v[i])
     return true;
   return false;
  }

  inline bool operator<(const Vector<T, N>& v) const {
   for (unsigned i = 0; i<N; i++) {
    if (_coord[i] < v[i])
     return true;
    if (_coord[i] > v[i])
     return false;
    if (_coord[i] == v[i])
     continue;
   }
   return false; 
  }

  inline bool operator>(const Vector<T, N>& v) const {
   for (unsigned i=0; i<N; i++) {
    if(_coord[i] > v[i])
     return true;
    if(_coord[i] < v[i])
     return false;
    if(_coord[i] == v[i])
     continue;
   }
   return false; 
  }

 protected:

  value_type _coord[N];
  enum {
   _dim = N,
  };
 };


 //
 //  Vec2 class (2D Vector)
 //    - T: value type
 //
 /////////////////////////////////////////////////////////////////////////////

 template <class T>
 class Vec2 : public Vector<T, 2>
 {
 public:

  typedef typename Vector<T, 2>::value_type value_type;

  inline Vec2() : Vector<T, 2>() {}

  template <class U>
  explicit inline Vec2(const U tab[2]) : Vector<T, 2>(tab) {}

  template <class U>
  explicit inline Vec2(const std::vector<U>& tab) : Vector<T, 2>(tab) {}

  template <class U>
  inline Vec2(const Vector<U, 2>& v) : Vector<T, 2>(v) {}

  inline Vec2(const value_type x,
   const value_type y = 0) : Vector<T, 2>() {
    this->_coord[0] = (T)x;
    this->_coord[1] = (T)y;
  }

  inline value_type x() const {
   return this->_coord[0];
  }

  inline value_type& x() {
   return this->_coord[0];
  }

  inline value_type y() const {
   return this->_coord[1];
  }

  inline value_type& y() {
   return this->_coord[1];
  }
 };


 //
 //  HVec3 class (3D Vector in homogeneous coordinates)
 //    - T: value type
 //
 /////////////////////////////////////////////////////////////////////////////

 template <class T>
 class HVec3 : public Vector<T, 4>
 {
 public:

  typedef typename Vector<T, 4>::value_type value_type;

  inline HVec3() : Vector<T, 4>() {}

  template <class U>
  explicit inline HVec3(const U tab[4]) : Vector<T, 4>(tab) {}

  template <class U>
  explicit inline HVec3(const std::vector<U>& tab) : Vector<T, 4>(tab) {}

  template<class U>
  inline HVec3(const Vector<U, 4>& v) : Vector<T, 4>(v) {}

  inline HVec3(const value_type sx,
   const value_type sy = 0,
   const value_type sz = 0,
   const value_type s = 1) {
    this->_coord[0] = sx;
    this->_coord[1] = sy;
    this->_coord[2] = sz;
    this->_coord[3] = s;
  }

  template <class U>
  inline HVec3(const Vector<U, 3>& sv) {
   this->_coord[0] = (T)sv[0];
   this->_coord[1] = (T)sv[1];
   this->_coord[2] = (T)sv[2];
   this->_coord[3] = (T)1;
  }


  template <class U>
  inline HVec3(const Vector<U, 3>& sv,
   const U) {
    this->_coord[0] = (T)sv[0];
    this->_coord[1] = (T)sv[1];
    this->_coord[2] = (T)sv[2];
    this->_coord[3] = (T)s;
  }

  inline value_type sx() const {
   return this->_coord[0];
  }

  inline value_type& sx() {
   return this->_coord[0];
  }

  inline value_type sy() const {
   return this->_coord[1];
  }

  inline value_type& sy() {
   return this->_coord[1];
  }

  inline value_type sz() const {
   return this->_coord[2];
  }

  inline value_type& sz() {
   return this->_coord[2];
  }

  inline value_type s() const {
   return this->_coord[3];
  }

  inline value_type& s() {
   return this->_coord[3];
  }

  // Acces to non-homogeneous coordinates in 3D

  inline value_type x() const {
   return this->_coord[0] / this->_coord[3];
  }

  inline value_type y() const {
   return this->_coord[1] / this->_coord[3];
  }

  inline value_type z() const {
   return this->_coord[2] / this->_coord[3];
  }
 };


 //
 //  Vec3 class (3D Vector)
 //    - T: value type
 //
 /////////////////////////////////////////////////////////////////////////////

 template <class T>
 class Vec3 : public Vector<T, 3>
 {
 public:

  typedef typename Vector<T, 3>::value_type value_type;

  inline Vec3() : Vector<T, 3>() {}

  template <class U>
  explicit inline Vec3(const U tab[3]) : Vector<T, 3>(tab) {}

  template <class U>
  explicit inline Vec3(const std::vector<U>& tab) : Vector<T, 3>(tab) {}

  template<class U>
  inline Vec3(const Vector<U, 3>& v) : Vector<T, 3>(v) {}

  template<class U>
  inline Vec3(const HVec3<U>& v) {
   this->_coord[0] = (T)v.x();
   this->_coord[1] = (T)v.y();
   this->_coord[2] = (T)v.z();
  }

  inline Vec3(const value_type x,
   const value_type y = 0,
   const value_type z = 0) : Vector<T, 3>() {
    this->_coord[0] = x;
    this->_coord[1] = y;
    this->_coord[2] = z;
  }

  inline value_type x() const {
   return this->_coord[0];
  }

  inline value_type& x() {
   return this->_coord[0];
  }

  inline value_type y() const {
   return this->_coord[1];
  }

  inline value_type& y() {
   return this->_coord[1];
  }

  inline value_type z() const {
   return this->_coord[2];
  }

  inline value_type& z() {
   return this->_coord[2];
  }
 };


 //
 //  Matrix class
 //    - T: value type
 //    - M: rows
 //    - N: cols
 //
 /////////////////////////////////////////////////////////////////////////////

 // Dirty, but icc under Windows needs this
# define _SIZE (M * N)

 template <class T, unsigned M, unsigned N>
 class Matrix
 {
 public:

  typedef T value_type;

  inline Matrix() {
   for (unsigned i = 0; i < _SIZE; i++)
    this->_coord[i] = 0;
  }

  ~Matrix() {
   internal::is_false<(M == 0)>::ensure();
   internal::is_false<(N == 0)>::ensure();
  }

  template <class U>
  explicit inline Matrix(const U tab[M][N]) {
   for (unsigned i = 0; i < M; i++)
    for (unsigned j = 0; j < N; j++)
     this->_coord[i * N + j] = tab[i][j];
  }

  template <class U>
  explicit inline Matrix(const U tab[_SIZE]) {
   for (unsigned i = 0; i < _SIZE; i++)
    this->_coord[i] = tab[i];
  }

  template <class U>
  explicit inline Matrix(const std::vector<U>& tab) {
   for (unsigned i = 0; i < _SIZE; i++)
    this->_coord[i] = tab[i];
  }

  template <class U>
  inline Matrix(const Matrix<U, M, N>& m) {
   for (unsigned i = 0; i < M; i++)
    for (unsigned j = 0; j < N; j++)
     this->_coord[i * N + j] = (T)m(i, j);
  }

  inline value_type operator()(const unsigned i, const unsigned j) const {
   return this->_coord[i * N + j];
  }

  inline value_type& operator()(const unsigned i, const unsigned j) {
   return this->_coord[i * N + j];
  }

  static inline unsigned rows() {
   return M;
  }

  static inline unsigned cols() {
   return N;
  }

  inline Matrix<T, M, N> transpose() const {
   Matrix<T, N, M> res;
   for (unsigned i = 0; i < M; i++)
    for (unsigned j = 0; j < N; j++)
     res(j,i) = this->_coord[i * N + j];
   return res;
  }

  inline void getArray(value_type res[M][N]) const {
   for (unsigned i = 0; i < M; i++)
    for (unsigned j = 0; j < N; j++)
     res[i][j] = this->_coord[i * N + j];
  }

  inline void getArray(value_type res[_SIZE]) const {
   for (unsigned i = 0; i < _SIZE; i++)
    res[i] = this->_coord[i];
  }

  inline const value_type* address() const {
   return this->_coord;
  }

  template <class U>
  inline Matrix<T, M, N>& operator=(const Matrix<U, M, N>& m) {
   if (this != &m)
    for (unsigned i = 0; i < M; i++)
     for (unsigned j = 0; j < N; j++)
      this->_coord[i * N + j] = (T)m(i, j);
   return *this;
  }

  template <class U>
  inline Matrix<T, M, N>& operator+=(const Matrix<U, M, N>& m) {
   for (unsigned i = 0; i < M; i++)
    for (unsigned j = 0; j < N; j++)
     this->_coord[i * N + j] += (T)m(i, j);
   return *this;
  }

  template <class U>
  inline Matrix<T, M, N>& operator-=(const Matrix<U, M, N>& m) {
   for (unsigned i = 0; i < M; i++)
    for (unsigned j = 0; j < N; j++)
     this->_coord[i * N + j] -= (T)m(i, j);
   return *this;
  }

  template <class U>
  inline Matrix<T, M, N>& operator*=(const U lambda) {
   for (unsigned i = 0; i < M; i++)
    for (unsigned j = 0; j < N; j++)
     this->_coord[i * N + j] *= lambda;
   return *this;
  }

  template <class U>
  inline Matrix<T, M, N>& operator/=(const U lambda) {
   if (lambda)
    for (unsigned i = 0; i < M; i++)
     for (unsigned j = 0; j < N; j++)
      this->_coord[i * N + j] /= lambda;
   return *this;
  }

 protected:

  value_type _coord[_SIZE];
 };


 //
 //  SquareMatrix class
 //    - T: value type
 //    - N: rows & cols
 //
 /////////////////////////////////////////////////////////////////////////////

 // Dirty, but icc under Windows needs this
# define __SIZE (N * N)

 template <class T, unsigned N>
 class SquareMatrix : public Matrix<T, N, N>
 {
 public:

  typedef T value_type;

  inline SquareMatrix() : Matrix<T, N, N>() {}

  template <class U>
  explicit inline SquareMatrix(const U tab[__SIZE]) : Matrix<T, N, N>(tab) {}

  template <class U>
  explicit inline SquareMatrix(const std::vector<U>& tab) : Matrix<T, N, N>(tab) {}

  template <class U>
  inline SquareMatrix(const Matrix<U, N, N>& m) : Matrix<T, N, N>(m) {}

  static inline SquareMatrix<T, N> identity() {
   SquareMatrix<T, N> res;
   for (unsigned i = 0; i < N; i++)
    res(i, i) = 1;
   return res;
  }
 };


 //
 // Vector external functions
 //
 /////////////////////////////////////////////////////////////////////////////

 template <class T, unsigned N>
 inline Vector<T, N> operator+(const Vector<T, N>& v1,
  const Vector<T, N>& v2) {
   Vector<T, N> res(v1);
   res += v2;
   return res;
 }

 template <class T, unsigned N>
 inline Vector<T, N> operator-(const Vector<T, N>& v1,
  const Vector<T, N>& v2) {
   Vector<T, N> res(v1);
   res -= v2;
   return res;
 }
 template <class T, unsigned N>
 inline Vector<T, N> operator*(const Vector<T, N>& v,
  const typename Vector<T, N>::value_type r) {
   Vector<T, N> res(v);
   res *= r;
   return res;
 }

 template <class T, unsigned N>
 inline Vector<T, N> operator*(const typename Vector<T, N>::value_type r,
  const Vector<T, N>& v) {
   Vector<T, N> res(v);
   res *= r;
   return res;
 }

 template <class T, unsigned N>
 inline Vector<T, N> operator/(const Vector<T, N>& v,
  const typename Vector<T, N>::value_type r) {
   Vector<T, N> res(v);
   if (r)
    res /= r;
   return res;
 }

 // dot product
 template <class T, unsigned N>
 inline typename Vector<T, N>::value_type operator*(const Vector<T, N>& v1,
  const Vector<T, N>& v2) {
   typename Vector<T, N>::value_type sum = 0;
   for (unsigned i = 0; i < N; i++)
    sum += v1[i] * v2[i];
   return sum;
 }

 // cross product for 3D Vectors
 template <typename T>
 inline Vec3<T> operator^(const Vector<T, 3>& v1,
  const Vector<T, 3>& v2) {
   Vec3<T> res(v1[1] * v2[2] - v1[2] * v2[1],
    v1[2] * v2[0] - v1[0] * v2[2],
    v1[0] * v2[1] - v1[1] * v2[0]);
   return res;
 }

 // stream operator
 template <class T, unsigned N>
 inline std::ostream& operator<<(std::ostream& s,
  const Vector<T, N>& v) {
   unsigned i;
   s << "[";
   for (i = 0; i < N - 1; i++)
    s << v[i] << ", ";
   s << v[i] << "]";
   return s;
 }


 //
 // Matrix external functions
 //
 /////////////////////////////////////////////////////////////////////////////

 template <class T, unsigned M, unsigned N>
 inline Matrix<T, M, N>
  operator+(const Matrix<T, M, N>& m1,
  const Matrix<T, M, N>& m2) {
   Matrix<T, M, N> res(m1);
   res += m2;
   return res;
 }

 template <class T, unsigned M, unsigned N>
 inline Matrix<T, M, N>
  operator-(const Matrix<T, M, N>& m1,
  const Matrix<T, M, N>& m2) {
   Matrix<T, M, N> res(m1);
   res -= m2;
   return res;
 }

 template <class T, unsigned M, unsigned N>
 inline Matrix<T, M, N>
  operator*(const Matrix<T, M, N>& m1,
  const typename Matrix<T, M, N>::value_type lambda) {
   Matrix<T, M, N> res(m1);
   res *= lambda;
   return res;
 }

 template <class T, unsigned M, unsigned N>
 inline Matrix<T, M, N>
  operator*(const typename Matrix<T, M, N>::value_type lambda,
  const Matrix<T, M, N>& m1) {
   Matrix<T, M, N> res(m1);
   res *= lambda;
   return res;
 }

 template <class T, unsigned M, unsigned N>
 inline Matrix<T, M, N>
  operator/(const Matrix<T, M, N>& m1,
  const typename Matrix<T, M, N>::value_type lambda) {
   Matrix<T, M, N> res(m1);
   res /= lambda;
   return res;
 }

 template <class T, unsigned M, unsigned N, unsigned P>
 inline Matrix<T, M, P>
  operator*(const Matrix<T, M, N>& m1,
  const Matrix<T, N, P>& m2) {
   unsigned i, j, k;
   Matrix<T, M, P> res;
   typename  Matrix<T, N, P>::value_type scale;

   for (j = 0; j < P; j++) {
    for (k = 0; k < N; k++) {
     scale = m2(k, j);
     for (i = 0; i < N; i++)
      res(i, j) += m1(i, k) * scale;
    }
   }
   return res;
 }

 template <class T, unsigned M, unsigned N>
 inline Vector<T, M>
  operator*(const Matrix<T, M, N>& m,
  const Vector<T, N>& v) {

   Vector<T, M> res;
   typename Matrix<T, M, N>::value_type scale;

   for (unsigned j = 0; j < M; j++) {
    scale = v[j];
    for (unsigned i = 0; i < N; i++)
     res[i] += m(i, j) * scale;
   }
   return res;
 }

 // stream operator
 template <class T, unsigned M, unsigned N>
 inline std::ostream& operator<<(std::ostream& s,
  const Matrix<T, M, N>& m) {
   unsigned i, j;
   for (i = 0; i < M; i++) {
    s << "[";
    for (j = 0; j < N - 1; j++)
     s << m(i, j) << ", ";
    s << m(i, j) << "]" << std::endl;
   }
   return s;
 }

} // end of namespace vecmat

#endif // VECMAT_H


原因是在windows的頭文件里max,min已經被定義成宏了,所以要出問題!
解決方法:

#ifdef max
#undef max
#endif
去掉max的定義。
min同上。

問題解決。

posted @ 2008-11-21 11:21 Alina-zl 閱讀(807) | 評論 (0)編輯 收藏

2008年11月19日

CString, QString, char*之間的轉換

傳給未分配內存的const char* (LPCTSTR)指針.
   CString cstr(asdd);
   const char* ch = (LPCTSTR)cstr;
   ch指向的地址和cstr相同。但由于使用const保證ch不會修改,所以安全.2.傳給未分配內存的指針.
    CString cstr = "ASDDSD";
    char *ch = cstr.GetBuffer(cstr1.GetLength() + 1);
    cstr.ReleaseBuffer();
    //修改ch指向的值等于修改cstr里面的值.
    //PS:用完ch后,不用delete ch,因為這樣會破壞cstr內部空間,容易造成程序崩潰.
3.第二種用法。把CString 值賦給已分配內存的char *。
    CString cstr1 = "ASDDSD";
    int strLength = cstr1.GetLength() + 1;
    char *pValue = new char[strLength];
    strncpy(pValue, cstr1, strLength);
4.第三種用法.把CString 值賦給已分配內存char[]數組.
    CString cstr2 = "ASDDSD";
    int strLength1 = cstr1.GetLength() + 1;
    char chArray[100];
    memset(chArray,0, sizeof(bool) * 100); //將數組的垃圾內容清空.
    strncpy(chArray, cstr1, strLength1);

如果上述都不行:
CString轉換為char*
        CString origCString("Hello, World!");
        wchar_t* wCharString = origCString.GetBuffer(origCString.GetLength()+1);
        size_t origsize = wcslen(wCharString) + 1;
        size_t convertedChars = 0;
        char *CharString;
        CharString=new char(origsize);
        wcstombs_s(&convertedChars, CharString, origsize, wCharString , _TRUNCATE);
        cout << CharString << endl;
成功輸出字符串"Hello,World"

原因:
原來在VC++ 2005以前,應用程序默認都是關閉對Unicode的支持的,而在VC2005中,默認打開了對它的支持,CString對應的字符串應該是TCHAR,TCHAR的定義是這樣的,
        #ifdef _UNICODE
        typedef wchar_t TCHAR    ;
        #else
        typedef char TCHAR;
        #endif
所以在工程中應該可以關閉對于Unicode的支持,從而可以直接轉換。這個做法是右擊工程名—〉Property—〉General中的character set中選擇notset,這樣,本文開頭的那段代碼就可以正確的執行了。


如何將QString轉換為char *或者相反

How can I convert a QString to char* and vice versa ?(trolltech)

Answer:
In order to convert a QString to a char*, then you first need to get a latin1 representation of the string by calling toLatin1() on it which will return a QByteArray. Then call data() on the QByteArray to get a pointer to the data stored in the byte array. See the documentation:

See the following example for a demonstration:

int main(int argc, char **argv)
{
 QApplication app(argc, argv);
 QString str1 = "Test";
 QByteArray ba = str1.toLatin1();
 const char *c_str2 = ba.data();
 printf("str2: %s", c_str2);
 return app.exec();  
}
Note that it is necessary to store the bytearray before you call data() on it, a call like the following
const char *c_str2 = str2.toLatin1().data();

will make the application crash as the QByteArray has not been stored and hence no longer exists.


To convert a char* to a QString you can use the QString constructor that takes a QLatin1String, e.g:

QString string = QString(QLatin1String(c_str2)) ;

 

還有其他多種方法:

方法一 -----------------------------------------
#define G2U(s) ( QTextCodec::codecForName("GBK")->toUnicode(s) )
#define U2G(s) ( QTextCodec::codecForName("GBK")->fromUnicode(s) )

QString str;
QCString cstr;

str = G2U("中文輸入");
cstr = U2G(str);

QCString有這樣一個重載運算符
operator const char * () const

可以這樣
printf("%s\n", (const char*) cstr);
或是copy出來
char buf[1024];
strcpy(buf, (const char*) cstr);

 

方法二 -----------------------------------------
如果是中文系統

直接用   (const char*) str.local8Bit()
例如
printf("%s", (const char*) str.local8Bit());

str是一個QString

方法三 -----------------------------------------
char str[64];
QTextCodec *textcod = QTextCodec::codecForName("GBK");
        QCString string1 = textcod ->fromUnicode(listbox1->currentText());
        strcpy(str,string1);

QString和Std::string

 從char*到 QString可以從fromLocal8Bit()轉化
std::string有c_str()的函數使再轉化為char*

QString有toAscii()記不清了


你可以看看.


又是我的粗心釀成大錯,我重新查看了一下Qt文檔,原來Qt可以直接從std::wstring產生一個QString,用QString::fromStdWString(const std::wstring &)這個靜態成員函數即可。我試了試用std::string的c_str()返回的char *構造的QString不能再保存原先的中文信息,而用std::wstring構造的QString則可以用qDebug()輸出原先的中文信息
GB編碼與UTF8編碼的轉換
在主函數app后加上這句:

QUOTE:

QTextCodec::setCodecForLocale(QTextCodec::codecForName("GB18030"));

 

然后是從UTF8編碼到GB編碼的字符串轉換方法:

QUOTE:


QString Utf8_To_GB(QString strText)
{
    return QString::fromUtf8(strText.toLocal8Bit().data());
}

 

至于從GB到UTF8,那大家就經常用了:

QUOTE:

QString GB_To_Utf8(char *strText)
{
    return QString::fromLocal8Bit(strText);
}

posted @ 2008-11-19 21:39 Alina-zl 閱讀(13292) | 評論 (1)編輯 收藏

僅列出標題  
<2025年9月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

導航

統計

常用鏈接

留言簿(1)

隨筆檔案

搜索

最新評論

閱讀排行榜

評論排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲毛片在线观看.| 久久精品国产一区二区三区| 欧美成人嫩草网站| 麻豆成人综合网| 亚洲国产毛片完整版| 亚洲高清一区二区三区| 欧美激情亚洲一区| 亚洲欧美日韩另类| 久久精品电影| 亚洲日本中文字幕| 制服诱惑一区二区| 国内精品美女在线观看| 亚洲国产精品美女| 国产精品久久久久毛片软件 | 欧美中文字幕在线观看| 精品电影在线观看| 999在线观看精品免费不卡网站| 欧美亚洲不卡| 女人天堂亚洲aⅴ在线观看| 欧美肥婆在线| 欧美在线免费| 欧美美女bbbb| 久久久久久网| 欧美色中文字幕| 久久影音先锋| 国产精品国产a级| 欧美成人精品激情在线观看| 欧美三级乱码| 亚洲东热激情| 国产欧美日韩一区二区三区| 亚洲国产精品ⅴa在线观看 | 欧美粗暴jizz性欧美20| 午夜精品区一区二区三| 你懂的成人av| 久久久成人网| 国产精品久久久久久久电影 | 一本色道久久88亚洲综合88| 久久国产高清| 午夜欧美精品| 欧美日韩妖精视频| 欧美激情第1页| 国内成+人亚洲+欧美+综合在线| 亚洲精品四区| 亚洲精品社区| 久久综合久久综合久久综合| 激情小说另类小说亚洲欧美| 亚洲美女精品久久| 亚洲日本一区二区| 久久久精品一区| 午夜精品在线观看| 欧美日韩亚洲不卡| 亚洲精品社区| 日韩视频―中文字幕| 久久一区二区三区国产精品| 欧美中文字幕在线视频| 国产精品v日韩精品| 99re亚洲国产精品| 一本色道久久| 欧美视频一区| 亚洲第一在线视频| 亚洲国产一区二区在线| 欧美.com| 亚洲精品中文字| 亚洲视频中文| 国产精品va在线播放| 99爱精品视频| 欧美一区二区三区在线观看视频| 欧美三级视频在线播放| 亚洲精品日韩久久| 亚洲永久免费av| 国产精品免费在线| 午夜精品在线| 免费成人高清| 亚洲精选视频在线| 欧美午夜片欧美片在线观看| 亚洲图片欧美日产| 欧美专区在线| 亚洲成人自拍视频| 欧美精品一区二区精品网| 亚洲老司机av| 欧美一区二区国产| 伊人久久成人| 欧美日韩精品免费观看| 一区二区欧美激情| 欧美制服丝袜| 亚洲精品中文字| 国产精品成人观看视频免费| 亚洲综合欧美| 亚洲成人在线网| 亚洲综合日韩在线| 激情久久综合| 欧美日韩国产一区| 欧美一区二区三区在线观看| 亚洲国产成人精品女人久久久 | 国产一区二区三区黄| 久久尤物视频| 亚洲一区999| 欧美大片一区二区| 亚洲欧美综合网| 亚洲国产mv| 国产精品任我爽爆在线播放 | 久久天天狠狠| 一区二区三区www| 美女91精品| 亚洲欧美日韩国产另类专区| 好男人免费精品视频| 欧美日韩精品一区视频 | 亚洲视频精品在线| 欧美激情免费在线| 欧美在线首页| 亚洲——在线| 99成人精品| 伊人婷婷欧美激情| 国产日韩精品一区二区| 欧美日韩精品免费观看| 六十路精品视频| 久久福利视频导航| 中文在线不卡视频| 亚洲美女诱惑| 亚洲激情电影在线| 毛片av中文字幕一区二区| 亚洲欧美久久久| 中文国产亚洲喷潮| 亚洲美洲欧洲综合国产一区| 极品尤物久久久av免费看| 国产精品自拍在线| 国产精品qvod| 欧美视频一二三区| 欧美日韩国产91| 欧美国产日韩精品免费观看| 久久天堂av综合合色| 久久精品av麻豆的观看方式| 亚洲欧美激情视频在线观看一区二区三区| 亚洲高清网站| 最新国产成人av网站网址麻豆| 欧美激情第二页| 欧美成人免费小视频| 欧美va天堂| 欧美激情片在线观看| 欧美国产先锋| 亚洲国产一区在线观看| 欧美黄色一区| 亚洲人成人77777线观看| 亚洲日本va午夜在线影院| 亚洲国产影院| 一区二区三区高清| 亚洲在线观看视频| 欧美一区二区三区久久精品| 欧美亚洲日本网站| 久久久国产一区二区| 久久夜色精品国产亚洲aⅴ| 久久蜜桃香蕉精品一区二区三区| 久久久久久夜| 你懂的一区二区| 欧美精选午夜久久久乱码6080| 欧美日韩国产综合新一区| 欧美日韩在线播放| 国产欧美日韩视频在线观看| 国产一区二区在线观看免费播放| 激情亚洲一区二区三区四区| 亚洲国产精品激情在线观看| 亚洲三级视频| 亚洲欧美一区二区原创| 欧美一区二区日韩一区二区| 久久国产乱子精品免费女| 免费高清在线视频一区·| 亚洲福利视频网站| 亚洲视频免费在线| 久久精品成人一区二区三区| 欧美激情第1页| 国产精品网站在线| 亚洲国产精品专区久久| 亚洲一区二区三| 久久一区精品| 99国产精品久久久久久久久久| 欧美一区高清| 欧美日本国产精品| 国内精品久久久久影院优| 99综合电影在线视频| 久久精品一本| 亚洲巨乳在线| 老司机精品福利视频| 国产精品久久久久久久久久久久久久| 国产在线精品二区| 一本色道久久综合亚洲精品按摩| 欧美一级一区| 亚洲精品在线免费| 久久色中文字幕| 国产精品一区二区三区观看| 亚洲人人精品| 久久亚洲综合色| 亚洲欧美日韩区| 欧美日韩在线亚洲一区蜜芽| 在线观看欧美视频| 久久精品久久综合| 亚洲色图综合久久| 欧美日韩亚洲91| 99国产精品久久| 亚洲高清视频一区| 久久婷婷成人综合色|