puzzle

接了一个QT写小游戏的项目,找到一个QT3编写的比较不错的开源的,现在改写到QT4,遇到一些问题。
总结一下,首先需要先看看帮助中的Porting to Qt 4一节,详细介绍了迁移过程。下面是我自己开发中遇到的:
0。
可以使用qt工具qt3to4把Qt3的程序代码移植成QT4

1。有些函数,在QT4中以打算不支持,使用#ifdef QT3_SUPPORT宏进行控制,如果用户仍然想用这些函数,需要在编译的时指定这个宏。但不建议使用旧版本的函数啦,所以,你可以查看旧函数的源代码,自己直接调用它调用的其他代替函数。比如QDialog有个setCaption函数,我们可以使用setWindowTitle来代替,等等。

2。
有些类也进行了修改,如QButtonGroup的基类由QWidget改成了QObject,因此变成了不可见的widget了。不在有标题以及其他界面的函数,也不能直接和layout进行关联。这个时候我们可以借助QGroupBox 来实现原来QButtonGroup的一些旧的和界面相关的功能。参考下下面的例子:
http://hi.baidu.com/ediwon/blog/item/9a28e21196147cc6a6ef3f94.html

3。
有些类名字改变了,或者没有了。如,QListBox 改变成了Q3ListBox。

4。QT4中,Qstring 转换const char*
方法一:
QString qstr("hello,word");
const char * p = qstr.toLocal8Bit().data();
方法二:
const char *p = qstr.toStdString().data();
转换过来的是常量

5.
windows下使用VS2003环境编译QT程序有的时候,有时出错:
c1xx : fatal error C1083: 无法打开源文件:“./GeneratedFiles/debug/moc_piecewidget.cpp”: No such file or directory
LINK : fatal error LNK1104: 无法打开文件“./Debug/moc_piecewidget.obj”
无法解析的外部命令qmetaobject
是因为没有生成moc文件,使用moc在命令行下可以进行编译
同时在集成开发环境中,可以修改*.vcproj文件中,在头文件一节修该,加入moc等命令,如下
< File >
                RelativePath
= " .srcprefs.h " >
</ File >

< File
                
RelativePath =".srcprefs.h" >
                
< FileConfiguration
                    
Name ="Release|Win32" >
                    
< Tool
                        
Name ="VCCustomBuildTool"
                        Description
="Moc&apos;ing prefs.h..."
                        CommandLine
="$(QTDIR)inmoc.exe -IGeneratedFiles -I$(QTDIR)include -I.GeneratedFilesRelease -I$(QTDIR)includeQtCore -I$(QTDIR)includeQtGui &quot;.srcprefs.h&quot; -o &quot;GeneratedFilesReleasemoc_prefs.cpp&quot;
"

                        AdditionalDependencies
="$(QTDIR)inmoc.exe;.srcprefs.h"
                        Outputs
="&quot;GeneratedFilesReleasemoc_prefs.cpp&quot;" />
                
</ FileConfiguration >
                
< FileConfiguration
                    
Name ="Debug|Win32" >
                    
< Tool
                        
Name ="VCCustomBuildTool"
                        Description
="Moc&apos;ing prefs.h..."
                        CommandLine
="$(QTDIR)inmoc.exe -IGeneratedFiles -I$(QTDIR)include -I.GeneratedFilesDebug -I$(QTDIR)includeQtCore -I$(QTDIR)includeQtGui &quot;.srcprefs.h&quot; -o &quot;GeneratedFilesDebugmoc_prefs.cpp&quot;
"

                        AdditionalDependencies
="$(QTDIR)inmoc.exe;.srcprefs.h"
                        Outputs
="&quot;GeneratedFilesDebugmoc_prefs.cpp&quot;" />
                
</ FileConfiguration >
            
</ File >
最后在后面的生成文件中加入:
< Filter
            Name
= " Generated Files "
            Filter
= " moc;h;cpp "
            UniqueIdentifier
= " {71ED8ED8-ACB9-4CE9-BBE1-E00B30144E11} " >
            
< File
                RelativePath
= " .generatedfilesdebugmoc_gamedialog.cpp " >
                
< FileConfiguration
                    Name
= " Release|Win32 "
                    ExcludedFromBuild
= " TRUE " >
                    
< Tool
                        Name
= " VCCLCompilerTool " />
                
</ FileConfiguration >
            
</ File >
            
< File
                RelativePath
= " .generatedfiles eleasemoc_gamedialog.cpp " >
                
< FileConfiguration
                    Name
= " Debug|Win32 "
                    ExcludedFromBuild
= " TRUE " >
                    
< Tool
                        Name
= " VCCLCompilerTool " />
                
</ FileConfiguration >
            
</ File >
</ Filter >
具体的实现,可以使用VS向导生成的文件,对照有问题的部分,仿照着修改就可以了。
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
单词搜索迷宫(Word Search Puzzle)问题是一个经典的算法问题,其输入是一个二维的字符数组和一组单词,目标是找出字符数组网格中的所有单词。这些单词可以是水平的、垂直的或者是任意的对角线方向,所以需要查找8个不同的方向。解决这个问题的一种常见方法是使用回溯算法,具体步骤如下: 1. 遍历二维字符数组,对于每个字符,以其为起点开始搜索,搜索的方向包括水平、垂直和对角线方向。 2. 对于每个搜索到的单词,将其记录下来。 3. 重复步骤1和2,直到遍历完整个二维字符数组。 下面是一个使用C#语言实现的单词搜索迷宫算法的示例代码: ```csharp class WordSearchPuzzle { private char[,] grid; private HashSet<string> words; public WordSearchPuzzle(char[,] grid, HashSet<string> words) { this.grid = grid; this.words = words; } public void Solve() { int rows = grid.GetLength(0); int cols = grid.GetLength(1); for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { Search(i, j, new StringBuilder()); } } } private void Search(int row, int col, StringBuilder sb) { if (row < 0 || row >= grid.GetLength(0) || col < 0 || col >= grid.GetLength(1)) { return; } sb.Append(grid[row, col]); string word = sb.ToString(); if (words.Contains(word)) { Console.WriteLine("Found '{0}' at [{1}, {2}] to [{3}, {4}]", word, row, col, row - sb.Length + 1, col - sb.Length + 1); } if (word.Length < 3) { Search(row + 1, col, sb); Search(row - 1, col, sb); Search(row, col + 1, sb); Search(row, col - 1, sb); Search(row + 1, col + 1, sb); Search(row - 1, col - 1, sb); Search(row + 1, col - 1, sb); Search(row - 1, col + 1, sb); } sb.Remove(sb.Length - 1, 1); } } // 使用示例 char[,] grid = new char[,] { {'t', 'h', 'i', 's'}, {'w', 'a', 't', 's'}, {'o', 'a', 'h', 'g'}, {'f', 'g', 'd', 't'} }; HashSet<string> words = new HashSet<string>() { "this", "two", "fat", "that" }; WordSearchPuzzle puzzle = new WordSearchPuzzle(grid, words); puzzle.Solve(); ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值