在Qt中,我可以使用该
方法获得selected texta .我该怎么办?QComboBoxcombobox->currentText()selected value
我寻求帮助,但找不到currentData()我希望找到的方法.我只能找到combobox->currentIndex()
除了之外,还有更聪明的方法combobox->itemData(combobox->currentIndex())吗?
更新:从Qt 5开始不再需要了.currentData()已经添加了一个方法http://doc.qt.io/qt-5/qcombobox.html#currentData-prop
我有一个web服务,我需要使用Qt POST一些数据.我认为在POST到Web服务时我可以使用QByteArray.
我的问题是,如何格式化这个数组,以便在另一端正确解析?
这是我到目前为止的代码:
// Setup the webservice url
QUrl serviceUrl = QUrl("http://myserver/myservice.asmx");
QByteArray postData;
/*
Setup the post data somehow
I want to transmit:
param1=string,
param2=string
*/
// Call the webservice
QNetworkAccessManager *networkManager = new QNetworkAccessManager(this);
connect(networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(serviceRequestFinished(QNetworkReply*)));
networkManager->post(QNetworkRequest(serviceUrl), postData);
Run Code Online (Sandbox Code Playgroud)
谢谢!
我正在尝试在我的网站上使用新的Facebook Graph API.这就是我所拥有的:
在页面的某个地方:
<fb:login-button autologoutlink="true" perms="email,user_birthday,status_update,publish_stream"></fb:login-button>
Run Code Online (Sandbox Code Playgroud)
标签后面:
<div id="fb-root">
</div>
<script type="text/javascript">
window.fbAsyncInit = function () {
FB.init({ appId: '<%= ConfigurationManager.AppSettings["FBAppId"] %>', status: true, cookie: true, xfbml: true });
/* All the events registered */
FB.Event.subscribe('auth.login', function (response) {
// do something with response
alert("login success");
});
FB.Event.subscribe('auth.logout', function (response) {
// do something with response
alert("logout success");
});
FB.getLoginStatus(function (response) {
if (response.session) {
// logged in and connected user, someone you know
alert("login success");
}
});
}; …Run Code Online (Sandbox Code Playgroud) 我试图找到设计数据库的最佳方法,以便允许以下场景:
我应该如何设计数据库来处理这种情况,因为我可能想要使用大学ID进行排序(可能仅针对内置大学而不是用户输入的大学)
谢谢!
我只是想让它类似于Facebook如何处理这种情况.如果用户选择他的教育(通过实际输入我不关心的组合框)并选择其中一个返回值,Facebook会做什么?
在我的猜测中,它会在多对多表中插入UserID和EducationID.现在如果用户输入的内容根本不在数据库中?它仍然存储在他的个人资料中,但在哪里?
我在C++中有以下结构:
struct routing_entry {
unsigned long destSeq; // 32 bits
unsigned long nextHop // 32 bits
unsigned char hopCount; // 8 bits
};
Run Code Online (Sandbox Code Playgroud)
我有以下功能:
routing_entry Cnode_router_aodv::consultTable(unsigned int destinationID ) {
routing_entry route;
if ( routing_table.find(destinationID) != routing_table.end() )
route = routing_table[destinationID];
return route; // will be "empty" if not found
}
Run Code Online (Sandbox Code Playgroud)
"routing_table"是一个stl :: map,定义如下:
map< unsigned long int, routing_entry > routing_table;
Run Code Online (Sandbox Code Playgroud)
我现在的问题是,当使用consultTable函数时,我想检查返回值是否实际初始化,Java伪代码中有些类似(因为我来自Java阵营):
Route consultTable(int id) {
Route r = table.find(id);
return r;
}
Run Code Online (Sandbox Code Playgroud)
然后检查r == null
我正在尝试创建一个UniqueAttribute使用System.ComponentModel.DataAnnotations.ValidationAttribute
我希望这是通用的,因为我可以传递Linq DataContext,表名,字段并验证传入值是否唯一.
这是一个不可编译的代码片段,我现在卡在这里:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;
using System.Data.Linq;
using System.ComponentModel;
namespace LinkDev.Innovation.Miscellaneous.Validation.Attributes
{
public class UniqueAttribute : ValidationAttribute
{
public string Field { get; set; }
public override bool IsValid(object value)
{
string str = (string)value;
if (String.IsNullOrEmpty(str))
return true;
// this is where I'm stuck
return (!Table.Where(entity => entity.Field.Equals(str)).Any());
}
}
}
Run Code Online (Sandbox Code Playgroud)
我应该在我的模型中使用它如下:
[Required]
[StringLength(10)]
[Unique(new DataContext(),"Groups","name")]
public string name { get; set; }
Run Code Online (Sandbox Code Playgroud)
编辑:请注意,根据这个:为什么C#禁止通用属性类型? 我不能使用属性的泛型类型.
所以我的新方法是使用Reflection/Expression树来动态构建Lambda表达式树.
我有一个具有以下UI形式的应用程序,这些形式来自QMainWindow
我应该登录到LoginWindow中的应用程序,然后将其移至TasksWindow。在TasksWindow中,我将从组合框中选择一个项目,然后移至DetailsWindow并填充与该项目相关的数据。在DetailsWindow上,我将执行菜单操作,以使我返回TasksWindow。
目前,我的想法(以及我尝试过的)是这样的。在main.cpp中:
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
LoginWindow loginWindow;
loginWindow.showMaximized();
return app.exec();
}
Run Code Online (Sandbox Code Playgroud)
并在LoginWindow按钮中:
void LoginWindow::on_loginButton_clicked()
{
this->hide(); // hide the login window
TasksWindow tasksWindow;
tasksWindow.showMaximized();
}
Run Code Online (Sandbox Code Playgroud)
有一个更好的方法吗?它变得难以管理,因为现在我必须包括对我应该去的每个窗口类的引用,可能会创建循环引用!
请注意,我正在这样做,并将应用程序编译为Qt Symbian应用程序。
在应用程序窗口之间切换的最佳方法是什么?我曾考虑过使用QStackedWidget,并进行了实际尝试,但是问题是我必须编写所有代码来处理同一文件中的不同事件,并且各个窗口的操作菜单也不同。
救命!:)
qt ×3
symbian ×2
c# ×1
c++ ×1
database ×1
facebook ×1
linq-to-sql ×1
null ×1
post ×1
qcombobox ×1
validation ×1
web-services ×1