我的代码出现在下面。当我尝试编译它时,我得到:
error: 29:38 comparison between distinct pointer types QAbstractButton and QPushButton* lacks a cast -> 'if (stdmetBox.clickedButton() == stdButton)'
系统:Amazon Kindle Fire 7"运行 Cyanogenmod 11.0 (Android 4.4.2 Kitkat) 编译器:G++/GCC(C4droid 插件版本 4.9.1 的 GCC) IDE:带有 SDL、GCC 和 Ministro 插件的 C4droid
如有任何帮助,我们将不胜感激。我已经搜索过,但我能找到的唯一实例是特定于 iOS 的。
#include <fstream>
#include <QApplication>
#include <QLabel>
#include <QMessageBox>
#include <QString>
#include <QAbstractButton>
#include <QInputDialog>
#include <QDebug>
using namespace std;
int setup()
{
string unitchar;
string unitcharo;
bool setupSuccess;
int returncode;
QMessageBox msgBox;
QMessageBox stdmetBox;
QMessageBox ynBox;
msgBox.setText("Welcome to Tyler's Fitness App! This app will help you with your fitness goals, whatever they may be. Let's get you set up!");
msgBox.exec();
QPushButton *stdButton = stdmetBox.addButton(QT_TR_NOOP("Standard"), QMessageBox::ActionRole);
QPushButton *metButton = stdmetBox.addButton(QT_TR_NOOP("Metric"), QMessageBox::ActionRole);
stdmetBox.exec();
if (stdmetBox.clickedButton() == stdButton)
{
unitchar = "standard";
unitcharo = "metric";
}
else if (stdmetBox.clickedButton() == metButton)
{
unitchar = "metric";
unitcharo = "standard";
}
else
{
setupSuccess = false;
returncode = 0;
return returncode;
}
if (unitchar == "standard")
{
ynBox.setInformativeText("Standard units include feet, miles, mph, pounds, etc.");
}
else
{
ynBox.setInformativeText("Metric units include meters, kilometers, kph, kilograms, etc.");
}
QPushButton *yesButton = ynBox.addButton(QT_TR_NOOP("Yes"), QMessageBox::ActionRole);
QPushButton *noButton = ynBox.addButton(QT_TR_NOOP("No"), QMessageBox::ActionRole);
ynBox.setText("Is that okay?")
while (ynBox.clickedButton() == noButton)
{
if (unitchar == "standard")
{
unitchar = "metric";
unitcharo = "standard";
}
else
{
unitchar = "standard";
unitcharo = "metric";
}
if (unitchar == "standard")
{
ynBox.setInformativeText("Standard units include feet, miles, mph, pounds, etc.");
}
else
{
ynBox.setInformativeText("Metric units include meters, kilometers, kph, kilograms, etc.");
}
result = ynBox.exec();
}
if (unitchar == "standard")
{
msgBox.setText("Great! You've selected standard units.");
msgBox.exec();
setupSuccess = true;
}
else
{
msgBox.setText("Great! You've selected metric units.");
msgBox.exec();
setupSuccess = true;
}
if (setupSuccess != true)
{
returncode = 0;
}
else if (unitchar == "standard")
{
returncode = 1;
}
else
{
returncode = 2;
}
return returncode;
}
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
unitmaster = setup();
if ((unitmaster == 1) || (unitmaster == 2))
{
QMessageBox successBox;
successBox.setText("The program has completed successfully!");
successBox.exec();
}
else
{
QMessageBox errorBox;
errorBox.setText("The program has completed successfully!");
errorBox.exec();
}
return app.exec();
}
最佳答案
您似乎忘记包含 <QPushButton>即使你使用 QPushButton以一种需要它的定义的方式。其中一个 header 必须声明它,因为它被识别为一种类型,但如果它不完整,那么编译器就不会知道 QPushButton*可转换为 QAbstractButton* .
作为一般规则,请始终包含定义您使用的类型的 header ,除非您确定声明就足够了。基指针的隐式转换是需要定义的东西。
关于android - QAbstractButton 和 QPushButton* 之间的比较缺少强制转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29649546/
我的目标是转换表单输入,例如“100兆字节”或“1GB”,并将其转换为我可以存储在数据库中的文件大小(以千字节为单位)。目前,我有这个:defquota_convert@regex=/([0-9]+)(.*)s/@sizes=%w{kilobytemegabytegigabyte}m=self.quota.match(@regex)if@sizes.include?m[2]eval("self.quota=#{m[1]}.#{m[2]}")endend这有效,但前提是输入是倍数(“gigabytes”,而不是“gigabyte”)并且由于使用了eval看起来疯狂不安全。所以,功能正常,
我想将html转换为纯文本。不过,我不想只删除标签,我想智能地保留尽可能多的格式。为插入换行符标签,检测段落并格式化它们等。输入非常简单,通常是格式良好的html(不是整个文档,只是一堆内容,通常没有anchor或图像)。我可以将几个正则表达式放在一起,让我达到80%,但我认为可能有一些现有的解决方案更智能。 最佳答案 首先,不要尝试为此使用正则表达式。很有可能你会想出一个脆弱/脆弱的解决方案,它会随着HTML的变化而崩溃,或者很难管理和维护。您可以使用Nokogiri快速解析HTML并提取文本:require'nokogiri'h
我需要读入一个包含数字列表的文件。此代码读取文件并将其放入二维数组中。现在我需要获取数组中所有数字的平均值,但我需要将数组的内容更改为int。有什么想法可以将to_i方法放在哪里吗?ClassTerraindefinitializefile_name@input=IO.readlines(file_name)#readinfile@size=@input[0].to_i@land=[@size]x=1whilex 最佳答案 只需将数组映射为整数:@land边注如果你想得到一条线的平均值,你可以这样做:values=@input[x]
这道题是thisquestion的逆题.给定一个散列,每个键都有一个数组,例如{[:a,:b,:c]=>1,[:a,:b,:d]=>2,[:a,:e]=>3,[:f]=>4,}将其转换为嵌套哈希的最佳方法是什么{:a=>{:b=>{:c=>1,:d=>2},:e=>3,},:f=>4,} 最佳答案 这是一个迭代的解决方案,递归的解决方案留给读者作为练习:defconvert(h={})ret={}h.eachdo|k,v|node=retk[0..-2].each{|x|node[x]||={};node=node[x]}node[
我构建了两个需要相互通信和发送文件的Rails应用程序。例如,一个Rails应用程序会发送请求以查看其他应用程序数据库中的表。然后另一个应用程序将呈现该表的json并将其发回。我还希望一个应用程序将存储在其公共(public)目录中的文本文件发送到另一个应用程序的公共(public)目录。我从来没有做过这样的事情,所以我什至不知道从哪里开始。任何帮助,将不胜感激。谢谢! 最佳答案 无论Rails是什么,几乎所有Web应用程序都有您的要求,大多数现代Web应用程序都需要相互通信。但是有一个小小的理解需要你坚持下去,网站不应直接访问彼此
我有一个围绕一些对象的包装类,我想将这些对象用作散列中的键。包装对象和解包装对象应映射到相同的键。一个简单的例子是这样的:classAattr_reader:xdefinitialize(inner)@inner=innerenddefx;@inner.x;enddef==(other)@inner.x==other.xendenda=A.new(o)#oisjustanyobjectthatallowso.xb=A.new(o)h={a=>5}ph[a]#5ph[b]#nil,shouldbe5ph[o]#nil,shouldbe5我试过==、===、eq?并散列所有无济于事。
在Cooper的书BeginningRuby中,第166页有一个我无法重现的示例。classSongincludeComparableattr_accessor:lengthdef(other)@lengthother.lengthenddefinitialize(song_name,length)@song_name=song_name@length=lengthendenda=Song.new('Rockaroundtheclock',143)b=Song.new('BohemianRhapsody',544)c=Song.new('MinuteWaltz',60)a.betwee
我正在检查一个Rails项目。在ERubyHTML模板页面上,我看到了这样几行:我不明白为什么不这样写:在这种情况下,||=和ifnil?有什么区别? 最佳答案 在这种特殊情况下没有区别,但可能是出于习惯。每当我看到nil?被使用时,它几乎总是使用不当。在Ruby中,很少有东西在逻辑上是假的,只有文字false和nil是。这意味着像if(!x.nil?)这样的代码几乎总是更好地表示为if(x)除非期望x可能是文字false。我会将其切换为||=false,因为它具有相同的结果,但这在很大程度上取决于偏好。唯一的缺点是赋值会在每次运行
我正在使用Rails构建一个简单的聊天应用程序。当用户输入url时,我希望将其输出为html链接(即“url”)。我想知道在Ruby中是否有任何库或众所周知的方法可以做到这一点。如果没有,我有一些不错的正则表达式示例代码可以使用... 最佳答案 查看auto_linkRails提供的辅助方法。这会将所有URL和电子邮件地址变成可点击的链接(htmlanchor标记)。这是文档中的代码示例。auto_link("Gotohttp://www.rubyonrails.organdsayhellotodavid@loudthinking.
我收到格式为的回复#我需要将其转换为哈希值(针对活跃商家)。目前我正在遍历变量并执行此操作:response.instance_variables.eachdo|r|my_hash.merge!(r.to_s.delete("@").intern=>response.instance_eval(r.to_s.delete("@")))end这有效,它将生成{:first="charlie",:last=>"kelly"},但它似乎有点hacky和不稳定。有更好的方法吗?编辑:我刚刚意识到我可以使用instance_variable_get作为该等式的第二部分,但这仍然是主要问题。